API «editer_objet»

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

  • New in : SPIP 3.0

Insert

A new instance of an editorial object is created in the database 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 keyword...)

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 the generic processing.

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

Modify

To modify an instance of an object in the database, 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 the 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».

Publish

For the publication of an object (change of status or date), you should call the same function objet_modifier 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 objet_instituer instead of generic processing.

The objet_instituer function checks the author’s rights of the current session to perform the action, via a call to 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».

Author jack Published : Updated : 23/07/23

Translations : English, français