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.
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
$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: