Coding with SPIP 3.0
SPIP3.0 Technical Documentation

> > > > ajouter_boutons

ajouter_boutons

This pipeline is used to add buttons to the private zone navigation menu. It is not really so useful since the creation of the <bouton> tag in the plugin.xml file (see Defining buttons).

  1. $boutons_admin = pipeline('ajouter_boutons', $boutons_admin);

The "ajouter_boutons" pipeline accepts a parameter table of "button identifer / button description" couples (with a PHP class of Bouton(Button)). A button can declare a sub-menu in the "submenu" variable of the Bouton(Button) class. You must create an instance of the Bouton class to define this:

  1. function plugin_ajouter_boutons($boutons_admin){
  2. $boutons_admin['identifier'] =
  3. new Bouton('image/du_bouton.png', 'Button title', 'url');
  4. $boutons_admin['identifier']->sousmenu['other_identifier'] =
  5. new Bouton('image/du_bouton.png', 'Button title', 'url');
  6. return $boutons_admin;
  7. }

Download

The third url parameter of the Bouton class is optional. By default, it will be an "exec" page with the same name as the identifier provided (ecrire/?exec=identifier).

Example

The "Thelia" plugin, which makes it possible to interface SPIP with the Thélia software package, uses this pipeline to add a link to the Thélia catalogue to the "Édition" menu (with the "naviguer" identifier):

  1. function spip_thelia_ajouter_boutons($boutons_admin) {
  2. // if you are admin
  3. if ($GLOBALS['visiteur_session']['statut'] == "0minirezo") {
  4. $boutons_admin['naviguer']->sousmenu['spip_thelia_catalogue'] =
  5. new Bouton(_DIR_PLUGIN_SPIP_THELIA . 'img_pack/logo_thelia_petit.png', 'Catalogue Th&eacute;lia');
  6. }
  7. return $boutons_admin;
  8. }

Download

Migration to the new system

To rewrite this example to the new system, two things would need to be separated: the button declaration, and the authorisation to view it or not (in this case, authorisation is only for administrators). The declaration is written in the plugin.xml file:

  1. <bouton id="spip_thelia_catalogue" parent="naviguer">
  2. <icone>smg_pack/logo_thelia_petit.png</icone>
  3. <titre>title language string</titre>
  4. </bouton>

Download

The authorisation component is built with a special authorisation function (use the autoriser pipeline to define this):

  1. function autoriser_spip_thelia_catalogue_bouton_dist($faire, $type, $id, $qui, $opt) {
  2. return ($qui['statut'] == '0minirezo');
  3. }

Download

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