El sistema Hooks: Difference between revisions

Jump to navigation Jump to search
Enhanced code snippet
(Enhanced code snippet)
Line 80: Line 80:
class ActionsYourModuleName  
class ActionsYourModuleName  
{  
{  
/**
    /** Overloading the doActions function : replacing the parent's function with the one below  
* Overloading the doActions function : replacing the parent's function with the one below
    * @param     parameters meta datas of the hook (context, etc...)  
*
    * @param     object             the object you want to process (an invoice if you are in invoice module, a propale in propale's module, etc...)  
* @param   array()        $parameters     Hook metadatas (context, etc...)
    * @param     action             current action (if set). Generally create or edit or null  
* @param   CommonObject    &$object       The object to process (an invoice if you are in invoice module, a propale in propale's module, etc...)
    * @return       void
* @param   string          &$action       Current action (if set). Generally create or edit or null
    */  
* @param  HookManager    $hookmanager    Hook manager propagated to allow calling another hook
    function doActions($parameters, &$object, &$action, $hookmanager)  
* @return int                            < 0 on error, 0 on success, 1 to replace standard code
    {  
*/
        print_r($parameters);  
function doActions($parameters, &$object, &$action, $hookmanager)
        echo "action: ".$action;
{
        print_r($object);
$error = 0; // Error counter
$myvalue = 'test'; // A result value
        if (in_array('somecontext',explode(':',$parameters['context'])))
        {
          // do something only for the context 'somecontext'
        }


        if (! $error)
print_r($parameters);
        {
echo "action: " . $action;
            $this->results=array('myreturn'=>$myvalue)
print_r($object);
            $this->resprints='A text to show';
 
            return 0; // or return 1 to replace standard code
if (in_array('somecontext', explode(':', $parameters['context'])))
        }
{
        else
  // do something only for the context 'somecontext'
        {
}
            $this->errors[]='Error message';
 
            return -1;
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>
Bureaucrats, emailconfirmed, Administrators
149

edits

Navigation menu