Submitted : API « editer_objet »

**SPIP**

# Article submitted

The article "**API «editer_objet»**
(SPIP)" is submitted
for publication. on Thursday 1 October 2020.

* * *

## API «editer_objet»

Thursday 1 October 2020 , by [jack](.././?page=auteur&id_auteur=593&)

Adding, editing, and publishing instances of editorial objects is
simplified by a programming interface (API - Wikipedia)
(or API) consisting of 3 generic functions that can be used to manipulate
all SPIP objects.

## Table of contents

* Insert
* Modify
* Publish

## Insert[|Back to the table of contents](#s-Insert)

A new instance of an editorial object is created in base by

    include_spip
    
    (

    'action/editer_objet'

    )

    ;

    $id_objet

    =
    
     objet_inserer
    
    (

    $objet

    ,

    $id_parent

    )

    ;

**`objet_inserer` ** takes 2 arguments:

* `$objet` is the name of the inserted object (article, news item,...)
* `$id_parent` (optional) is the parent ID of the object (id\_rubrique
for an article or a news item, id\_groupe for a word...)

From ** SPIP 3.0 **, the function can take an optional third argument: an

array containing the values associated with each field.

The *pre_insertion* and *post_insertion* pipelines are called automatically
by the function.

If, for the requested object, a specific `xxx_inserer` function exists in
`action/editer_xxx`, it will be automatically called by `objet_inserer`
instead of generic processing.

The function returns the id of the record added in base, or 0 in case of
failure.

## Modify[|Back to the table of contents](#s-Modify)

To modify an instance of an object in base, we use the function:
**`objet_modifier`**

    include_spip
    
    (

    'action/editer_objet'

    )

    ;

    objet_modifier
    
    (

    $objet

    ,

    $id_objet

    ,

    $set

    )

    ;

The 3 arguments:

* `$objet` specifies the name of the modified object
* `$id_objet` gives the ID of the modified object
* `$set` is an associative array field => value of changed fields

The function automatically calls the *pre_edition* and *post_edition*
pipelines.

If for the requested object, a specific `xxx_modifier` function exists in
`action/editer_xxx`, it will be automatically called by `objet_modifier`
instead of generic processing.

The function returns an empty string if everything went well or the error
if failed.

The function `objet_modifier` checks the author’s rights of the current
session to take the action, via a call to `autoriser('modifier', $objet,
$id_objet)`. If it is called by an anonymous task, it will be necessary to
grant an exceptional permission as indicated in API «autoriser»
(SPIP).

## Publish[|Back to the table of contents](#s-Publish)

For the publication of an object (change of status or date), you should
call the same function < code>objet_modifier </code> in the same way as for
the change.

This function delegates to **`objet_instituer `** the updating of fields
that concern the status of the object. This makes it possible to edit the
content of an object and publish it in a single call.

If a `xxx_instituer` function exists in `action/editer_xxx` it will be
automatically called by </code> instead of generic processing.

The `objet_instituer</code > function checks the author's rights of the
current session to perform the action, via a call to
<code>autoriser('instituer', $objet, $id_objet)`. If it is called by an
anonymous task, it will be necessary to grant an exceptional permission as
indicated in API «autoriser»
(SPIP).

— Sent by SPIP (https://www.spip.net/)

rubon57-4eda4.jpg