I’ve been playing around with Dolibarr and I think I can follow most of the logic now, but this one has me a little perplexed. As usual, maybe it’s lack of sleep.
I recreated the commande/card.php in my own custom module and tried to use a hook to trigger my own printObjectLine function. The Hook is triggering, but is throwing an error.
The error makes sense looking at the function itself. There’s a mismatch in the number of arguments being passed, which makes me wonder how the commande version is even working?
It calls $object->formAddObjectLine(1, $mysoc, $soc);
However, the function is expecting at least 8 arguments:
public function printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected = 0, $extrafieldsline = 0, $defaulttpldir = ‘/core/tpl’);
I thought maybe it is being overloaded somewhere, but I did a grep search through all of the Dolibarr code and that’s the only time that function is set.
Dear da2310,
I guess by now you somehow solved your problem?
When I use the hooks on formAddObjectLine and printObjectLine the following warnings appear: Declaration of ActionsMyModule::formAddObjectLine($parameters, &$object, &$action, $hookmanager) should be compatible with CommonObject::formAddObjectLine($dateSelector, $seller, $buyer, $defaulttpldir = '/core/tpl') in C:\wamp64\www\dolibarr\htdocs\custom\MyModule\class\actions_MyModule.class.php on line *0* Declaration of ActionsMyModule::printObjectLine($parameters, &$object, &$action, $hookmanager) should be compatible with CommonObject::printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected = 0, $extrafields = NULL, $defaulttpldir = '/core/tpl') in C:\wamp64\www\dolibarr\htdocs\custom\MyModule\class\actions_MyModule.class.php on line *0*
(hookmanager.class.php 114)
The Module Builder generates this code where I did uncomment the call for function formAddObjectLine because I would get it called twice otherwise:
if ($object->status == 0 && $permissiontoadd && $action != ‘selectlines’)
{
if ($action != ‘editline’)
{
// Add products/services form
// Hook is used, formAddObjectLine would be displayed twice
//$object->formAddObjectLine(1, $mysoc, $soc);
$parameters = array();
$reshook = $hookmanager->executeHooks(‘formAddObjectLine’, $parameters, $object, $action); // Note that $action and $object may have been modified by hook
}
}
$object->formAddObjectLine(1, $mysoc, $soc) is not the hook, but it is the method of CommonObject (the class from which all other objects are extended) that is called in case there is no formAddObjectLine hook (in fact below you find an if (empty($reshook))).
If you look in the code, a couple of lines above, you’ll find $reshook = $hookmanager->executeHooks(‘formAddObjectLine’, $parameters, $object, $action);.
This the hook, to use it follow the steps in the documentation. Hooks system
It is poorly written and inaccurate but it is the only shred of documentation you can find