Line 1,160:
Line 1,160:
=Custom substitution variables=
=Custom substitution variables=
Custom substitution variables can be added by external modules.
Custom substitution variables can be added by external modules.
−
For this, the external module must embed a file called '''mymodule/core/substitutions/functions_mymodules.lib.php'''
+
For this, the external module must embed a file called '''mymodule/core/substitutions/functions_mymodules.lib.php''' and set the ->multipart['substitution'] = 1 into the module descriptor.
+
+
= How it work =
+
The array to define all substitution variables is defined in code by calling the method
+
<code>$substitutionarray = getCommonSubstitutionArray().</code>
+
This method receive the $object in parameter, so it can define the content of the substitution array using properties of this object.
+
+
Then the array will be used by calling the make_substitutions() this way:
+
<code>$textcompleted = make_substitutions($textwithsubtitutionkeys, $substitutionarray)</code>
+
+
However, sometimes to value to use is not available into the $object, neither into the environment, and it needs a database access to get the value.
+
In such a case, the substitution is not done by the getCommonSubstitutionArray(). The getCommonSubstitutionArray() will just add an entry into the array of substitution with the information to explain how to get the value like for this entry:
+
<code>$substitutionarray['__PROJECT_NAME__@lazyload'] = '/projet/class/project.class.php:Project:fetchAndSetSubstitution:'.$object->id</code>
+
The substitution will be done by the make_substitutions() and only it is required by calling the method defined (here fetchAndSetSubstitution with the param $object->id of the object Project defined into file /projet/class/project.class.php).
+
Thus, the heavy database access is done only if required.