From 3d82f0965ec3747002232d821f7a8e1087126dfd Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Mon, 29 Sep 2014 15:20:54 +0200 Subject: [PATCH] Fix: Try to filter by context, use the test with $currentcontext in method for avoid to run twice (I have not found any other solution!) --- htdocs/core/class/hookmanager.class.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/hookmanager.class.php b/htdocs/core/class/hookmanager.class.php index 52dc25dd452..c402353e8d7 100644 --- a/htdocs/core/class/hookmanager.class.php +++ b/htdocs/core/class/hookmanager.class.php @@ -156,6 +156,8 @@ class HookManager { if (! empty($modules)) { + $modulealreadyexecuted[$context]=array(); // Filter by context + foreach($modules as $module => $actionclassinstance) { //print "Before hook ".get_class($actionclassinstance)." method=".$method." hooktype=".$hooktype." results=".count($actionclassinstance->results)." resprints=".count($actionclassinstance->resprints)." resaction=".$resaction." result=".$result."
\n"; @@ -164,8 +166,8 @@ class HookManager // jump to next class if method does not exists if (! method_exists($actionclassinstance,$method)) continue; // test to avoid to run twice a hook, when a module implements several active contexts - if (in_array($module,$modulealreadyexecuted)) continue; - $modulealreadyexecuted[$module]=$module; + if (in_array($module,$modulealreadyexecuted[$context])) continue; + $modulealreadyexecuted[$context][$module]=$module; // Use the $currentcontext in method for avoid to run twice // Add current context for avoid method execution in bad context, you can add this test in your method : eg if($currentcontext != 'formfile') return; $parameters['currentcontext'] = $context; // Hooks that must return int (hooks with type 'addreplace')