Bureaucrats, emailconfirmed, Administrators
149
edits
Rdoursenaud (talk | contribs) (Enhanced code snippet) |
|||
| Line 80: | Line 80: | ||
class ActionsYourModuleName | class ActionsYourModuleName | ||
{ | { | ||
/** | |||
* Overloading the doActions function : replacing the parent's function with the one below | |||
* | |||
* @param array() $parameters Hook metadatas (context, etc...) | |||
* @param CommonObject &$object The object to process (an invoice if you are in invoice module, a propale in propale's module, etc...) | |||
* @param string &$action Current action (if set). Generally create or edit or null | |||
* @param HookManager $hookmanager Hook manager propagated to allow calling another hook | |||
* @return int < 0 on error, 0 on success, 1 to replace standard code | |||
*/ | |||
function doActions($parameters, &$object, &$action, $hookmanager) | |||
{ | |||
$error = 0; // Error counter | |||
$myvalue = 'test'; // A result value | |||
print_r($parameters); | |||
echo "action: " . $action; | |||
print_r($object); | |||
if (in_array('somecontext', explode(':', $parameters['context']))) | |||
{ | |||
// do something only for the context 'somecontext' | |||
} | |||
if (! $error) | |||
{ | |||
$this->results = array('myreturn' => $myvalue); | |||
$this->resprints = 'A text to show'; | |||
return 0; // or return 1 to replace standard code | |||
} | |||
else | |||
{ | |||
$this->errors[] = 'Error message'; | |||
return -1; | |||
} | |||
} | |||
} | } | ||
</source> | </source> | ||