Coding with SPIP 3.0
SPIP3.0 Technical Documentation

> > > > pre_insertion

pre_insertion

This pipeline is used to add default content when a new editorial element is being inserted into the database.

When an editorial item is requested to be saved, it has not yet been allocated a unique identifier (implying it is a new item), so an identifier is automatically created for that item using the insert_xx functions, where xx is the name of the intended object. This insertion pipeline has the simple goal of returning an identifier and saving the item’s default values. The pipeline is called from these insert_xx functions.

Once the identifier has been established, the normal modification tasks are performed using the xx_set and modifier_contenu functions which call the pre_edition and post_edition pipelines. Those tasks are the ones that will save the data entered by the user, and which will therefore do so even for new items.

This pipeline passes the table name and an array of fields and default values to be inserted:

  1. $champs = pipeline('pre_insertion',
  2. 'args' => array(
  3. 'table' => 'spip_rubriques',
  4. ),
  5. 'data' => $champs
  6. )
  7. );

Download

Example

The "Forum" plugin adds the forum status value for an article when it is created using the code below:

  1. function forum_pre_insertion($flux){
  2. if ($flux['args']['table']=='spip_articles'){
  3. $flux['args']['data']['accepter_forum'] = substr($GLOBALS['meta']['forums_publics'], 0, 3);
  4. }
  5. return $flux;
  6. }

Download

  • Author :
  • Published :
  • Updated : 29/05/10
  • Translations : English, français