You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There seems to be an issue with the propagation of the results variable within the HookManager class in Dolibarr, specifically when using the menuLeftMenuItems method in custom hooks. The $hookmanager->results are not automatically propagated to $actionclassinstance->results after the hook execution, which forces a manual assignment for the desired result to take effect.
The following workaround (manual result assignment) solves the issue temporarily, but this behavior seems unintended:
// Manual result propagation workaround
if (!empty($this->results)) {
$actionclassinstance->results = $this->results;
}
This manual propagation should not be necessary and suggests a bug in how HookManager handles the hook execution process.
Workaround:
o temporarily resolve the issue, I’ve had to manually force the propagation of results by adding this snippet in hookmanager.class.php:
if (!empty($this->results)) {
$actionclassinstance->results = $this->results;
}
Dolibarr Version
20.0.0
Environment PHP
8.2
Environment Database
pgsql
Steps to reproduce the behavior and expected behavior
Create a custom hook for modifying the left menu, specifically using menuLeftMenuItems.
Assign new menu items to $hookmanager->results.
Observe that the menu does not reflect the changes unless you manually assign $hookmanager->results to $actionclassinstance->results.
Code Snippet:
Here is the hook implementation:
function menuLeftMenuItems($parameters, &$object, &$action, &$hookmanager) {
// Log the start of the modification
dol_syslog("Hook: Starting menu modification", LOG_DEBUG);
// Modify the menu by adding a new item
$object[] = array(
'url' => '/custom/new_option.php',
'titre' => 'New Option',
'level' => 0,
'enabled' => 1,
);
// Assign changes to hookmanager
$hookmanager->results = array_values($object);
dol_syslog("After assigning to hookmanager->results: " . var_export($hookmanager->results, true), LOG_DEBUG);
return 1; // Replace the entire menu
}
Attached files
No response
The text was updated successfully, but these errors were encountered:
Bug
There seems to be an issue with the propagation of the results variable within the HookManager class in Dolibarr, specifically when using the menuLeftMenuItems method in custom hooks. The $hookmanager->results are not automatically propagated to $actionclassinstance->results after the hook execution, which forces a manual assignment for the desired result to take effect.
The following workaround (manual result assignment) solves the issue temporarily, but this behavior seems unintended:
This manual propagation should not be necessary and suggests a bug in how HookManager handles the hook execution process.
Workaround:
o temporarily resolve the issue, I’ve had to manually force the propagation of results by adding this snippet in hookmanager.class.php:
Dolibarr Version
20.0.0
Environment PHP
8.2
Environment Database
pgsql
Steps to reproduce the behavior and expected behavior
Create a custom hook for modifying the left menu, specifically using menuLeftMenuItems.
Assign new menu items to $hookmanager->results.
Observe that the menu does not reflect the changes unless you manually assign $hookmanager->results to $actionclassinstance->results.
Code Snippet:
Here is the hook implementation:
Attached files
No response
The text was updated successfully, but these errors were encountered: