Commit 1fdf2817 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

:sparkles: feat(dev-manual) Adapt documentation to last simplePlugin changes

issue #26
Showing with 32 additions and 26 deletions
+32 -26
...@@ -10,7 +10,6 @@ simplePlugin special attributes ...@@ -10,7 +10,6 @@ simplePlugin special attributes
There are some attributes that you can set in your class or in your constructor that will allow you to do more things: There are some attributes that you can set in your class or in your constructor that will allow you to do more things:
* Set **displayHeader** to TRUE if you need this tab to be deactivable. * Set **displayHeader** to TRUE if you need this tab to be deactivable.
* Set **mainTab** to TRUE if this plugin is the main tab.
* Set **preInitAttributes** to an array of attributes names to be sure they'll be initialized before the others (it's used by workstationGeneric for the network attribute) * Set **preInitAttributes** to an array of attributes names to be sure they'll be initialized before the others (it's used by workstationGeneric for the network attribute)
custom template custom template
...@@ -64,7 +63,7 @@ You can change it, doing something that look like that: ...@@ -64,7 +63,7 @@ You can change it, doing something that look like that:
.. code-block:: php .. code-block:: php
<?php <?php
function execute() function execute ()
{ {
$smarty = get_smarty(); $smarty = get_smarty();
parent::execute(); parent::execute();
...@@ -89,7 +88,7 @@ You can inherit it as follows: ...@@ -89,7 +88,7 @@ You can inherit it as follows:
.. code-block:: php .. code-block:: php
<?php <?php
function save_object() function save_object ()
{ {
parent::save_object(); parent::save_object();
if (isset($_POST[get_class($this)."_posted"])) { if (isset($_POST[get_class($this)."_posted"])) {
...@@ -106,7 +105,7 @@ You can inherit it and do some additionnal LDAP modifications when saving: ...@@ -106,7 +105,7 @@ You can inherit it and do some additionnal LDAP modifications when saving:
.. code-block:: php .. code-block:: php
<?php <?php
function ldap_save() protected function ldap_save (): array
{ {
$errors = parent::ldap_save(); $errors = parent::ldap_save();
...@@ -128,28 +127,34 @@ Your code should modify **$this->attrs** as ldap_save will write it into the LDA ...@@ -128,28 +127,34 @@ Your code should modify **$this->attrs** as ldap_save will write it into the LDA
.. code-block:: php .. code-block:: php
<?php <?php
function prepare_save() protected function prepare_save (): array
{ {
parent::prepare_save(); $errors = parent::prepare_save();
if (!empty($errors)) {
return $errors;
}
// your code goes here // your code goes here
return $errors;
} }
__construct __construct
^^^^^^^^^^^ ^^^^^^^^^^^
Of course, there is always the possibility to have your own constructor, just remember to call the parent one at the end. Of course, there is always the possibility to have your own constructor, just remember to call the parent one.
The simple plugin constructor have a 3rd optional parameter which is the attributes information. If you don't give it, the **getAttributesInfo** static function will be used. The simple plugin constructor have a 5th optional parameter which is the attributes information. If you don't give it, the **getAttributesInfo** static function will be used.
So you can do the following: So you can do the following:
.. code-block:: php .. code-block:: php
<?php <?php
function __construct($dn = NULL, $object = NULL) function __construct (string $dn = NULL, $object = NULL, $parent = NULL, bool $mainTab = FALSE)
{ {
$attributesInfo = self::getAttributesInfo(); $attributesInfo = self::getAttributesInfo();
// some modifications on $attributesInfo // some modifications on $attributesInfo
parent::__construct($dn, $object, $attributesInfo); parent::__construct($dn, $object, $parent, $mainTab, $attributesInfo);
} }
An other method, often simpler, is to modify your attributes after being constructed. You can't do that for all modifications but for common cases like SelectAttribute choices modification, it's what you should do: An other method, often simpler, is to modify your attributes after being constructed. You can't do that for all modifications but for common cases like SelectAttribute choices modification, it's what you should do:
...@@ -157,9 +162,9 @@ An other method, often simpler, is to modify your attributes after being constru ...@@ -157,9 +162,9 @@ An other method, often simpler, is to modify your attributes after being constru
.. code-block:: php .. code-block:: php
<?php <?php
function __construct($dn = NULL, $object = NULL) function __construct (string $dn = NULL, $object = NULL, $parent = NULL, bool $mainTab = FALSE, array $attributesInfo = NULL)
{ {
parent::__construct($dn, $object); parent::__construct($dn, $object, $parent, $mainTab, $attributesInfo);
$array = array('node1','node2'); // some dummy array $array = array('node1','node2'); // some dummy array
// After simplePlugin constructor, you must access attributes by their ldap name // After simplePlugin constructor, you must access attributes by their ldap name
...@@ -172,7 +177,7 @@ is_this_account ...@@ -172,7 +177,7 @@ is_this_account
This method is used to check if an object has your plugin tab activated or not. This method is used to check if an object has your plugin tab activated or not.
By default it will just return TRUE if the objectClasses of your tab are present and FALSE otherwise, it is usually correct. If you need an other behaviour, you will have to override it. By default it will just return TRUE if the objectClasses of your tab are present and FALSE otherwise, it is usually correct. If you need an other behaviour, you will have to override it.
function is_this_account($attrs) function is_this_account ($attrs)
Even if the method is not static, it’s not supposed to use the object attributes and should only use the information in the attrs parameter to tell if the LDAP node has this tab activated or not. Even if the method is not static, it’s not supposed to use the object attributes and should only use the information in the attrs parameter to tell if the LDAP node has this tab activated or not.
...@@ -222,7 +227,7 @@ For this, you can use the **setManagedAttributes** method as follow: ...@@ -222,7 +227,7 @@ For this, you can use the **setManagedAttributes** method as follow:
.. code-block:: php .. code-block:: php
$this->attributesAccess['boolean']->setManagedAttributes ( $this->attributesAccess['boolean']->setManagedAttributes(
array( array(
'disable' => array ( 'disable' => array (
FALSE => array ( FALSE => array (
...@@ -240,7 +245,7 @@ You can also use this method with selectattributes: ...@@ -240,7 +245,7 @@ You can also use this method with selectattributes:
.. code-block:: php .. code-block:: php
$this->attributesAccess['select']->setManagedAttributes ( $this->attributesAccess['select']->setManagedAttributes(
array( array(
'multiplevalues' => array ('darkcolors' => array('blue','black')), 'multiplevalues' => array ('darkcolors' => array('blue','black')),
'erase' => array ( 'erase' => array (
......
...@@ -28,6 +28,9 @@ This static method returns an array containing keys from the following table. So ...@@ -28,6 +28,9 @@ This static method returns an array containing keys from the following table. So
plProvidedAcls, "Array of acls", See full documentation below , empty plProvidedAcls, "Array of acls", See full documentation below , empty
plForeignKeys, "Array of foreign keys", See full documentation below , empty plForeignKeys, "Array of foreign keys", See full documentation below , empty
plManages, "Array of managed objectTypes (only for management classes)", Used to create links to objects of these types, empty plManages, "Array of managed objectTypes (only for management classes)", Used to create links to objects of these types, empty
plFilter, "LDAP filter", "Used to test if the tab is active", "Generated from plObjectClass"
plObjectClass, "Array of objectClasses", These objectClasses are added when the tab is saved, empty
plSearchAttrs, "Array of attributes", "Used in management classes for text search", empty
plSection plSection
--------- ---------
...@@ -43,7 +46,7 @@ You can also create a new menu section in this attribute using the following syn ...@@ -43,7 +46,7 @@ You can also create a new menu section in this attribute using the following syn
<?php <?php
array('mysection' => array('name' => _('My section'), 'priority' => 100)) array('mysection' => array('name' => _('My section'), 'priority' => 100))
Replace *mysection* with a lowercase id for your section and *My section* with the name to display in the menu. Replace *mysection* with a lowercase id for your section and *My section* with the name to display in the menu.
The existing sections are: The existing sections are:
...@@ -72,7 +75,7 @@ ObjectType definition is an array containing the following keys: ...@@ -72,7 +75,7 @@ ObjectType definition is an array containing the following keys:
name, Displayable name for this object type, **mandatory** name, Displayable name for this object type, **mandatory**
description, Displayable description for this object type, **mandatory** description, Displayable description for this object type, **mandatory**
filter, LDAP filter to find objects of this type, **mandatory** filter, LDAP filter to find objects of this type, value of plFilter
mainAttr, LDAP attribute to use in dn, cn mainAttr, LDAP attribute to use in dn, cn
nameAttr, LDAP attribute to use in object links, *mainAttr* nameAttr, LDAP attribute to use in object links, *mainAttr*
tabClass, PHP class to use for tab handling, simpleTabs tabClass, PHP class to use for tab handling, simpleTabs
...@@ -89,11 +92,11 @@ For instance, this is the plObjectType of the user class: ...@@ -89,11 +92,11 @@ For instance, this is the plObjectType of the user class:
<?php <?php
'plObjectType' => array( 'plObjectType' => array(
'user' => array( 'user' => array(
'description' => _('Users'),
'name' => _('User'), 'name' => _('User'),
'filter' => 'objectClass=gosaAccount', 'description' => _('User account'),
'mainAttr' => 'cn', 'mainAttr' => 'uid',
'icon' => 'geticon.php?context=types&amp;icon=user&amp;size=16', 'nameAttr' => 'cn',
'icon' => 'geticon.php?context=types&icon=user&size=16',
'ou' => get_ou('userRDN'), 'ou' => get_ou('userRDN'),
) )
), ),
...@@ -143,9 +146,9 @@ If you do need to specify ACL categories, you can create an acl category by spec ...@@ -143,9 +146,9 @@ If you do need to specify ACL categories, you can create an acl category by spec
<?php <?php
'plCategory' => array( 'plCategory' => array(
'acl' => array( 'acl' => array(
'description' => _('ACL'), 'description' => _('ACL'),
'objectClass' => array('gosaAcl','gosaRole') 'objectClass' => array('gosaAcl','gosaRole')
) )
), ),
An ACL category only contains a description and a list of LDAP objectClasses (for some historical reason) An ACL category only contains a description and a list of LDAP objectClasses (for some historical reason)
...@@ -41,9 +41,6 @@ This is the code for an empty plugin: ...@@ -41,9 +41,6 @@ This is the code for an empty plugin:
// we want it activated on all objects // we want it activated on all objects
var $displayHeader = FALSE; var $displayHeader = FALSE;
// Here we indicate which LDAP classes our plugin is using.
var $objectclasses = array('demoPlugin');
// We need this function that returns some information about the plugin // We need this function that returns some information about the plugin
static function plInfo () static function plInfo ()
{ {
...@@ -53,6 +50,7 @@ This is the code for an empty plugin: ...@@ -53,6 +50,7 @@ This is the code for an empty plugin:
'plDescription' => _('Edit some useless personal information'), 'plDescription' => _('Edit some useless personal information'),
'plSelfModify' => TRUE, // Does this plugin have an owner that might be able to edit its entry 'plSelfModify' => TRUE, // Does this plugin have an owner that might be able to edit its entry
'plObjectType' => array('user'), 'plObjectType' => array('user'),
'plObjectClass' => array('demoPlugin'),
// simplePlugin can generate the ACL list for us // simplePlugin can generate the ACL list for us
'plProvidedAcls' => parent::generatePlProvidedAcls(self::getAttributesInfo()) 'plProvidedAcls' => parent::generatePlProvidedAcls(self::getAttributesInfo())
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment