Weird Hook Issue

Hi,

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

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.

What am I missing?

Thank you in advance!

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
}
}

Hi davidb,

I don’t remember how I dealt with it at the time, but likely just wrote something to bypass it.