CRM-19813 - CRM_Utils_Hook::invoke() - Use dispatcher when possible
authorTim Otten <totten@civicrm.org>
Tue, 7 Mar 2017 22:13:31 +0000 (14:13 -0800)
committerTim Otten <totten@civicrm.org>
Thu, 30 Mar 2017 22:39:52 +0000 (15:39 -0700)
CRM/Utils/Hook.php

index 2636f4527530e727d8345487609c1c7c13c237f7..9446f30c84eb299c8c27a48700988a552ac856d5 100644 (file)
@@ -156,8 +156,18 @@ abstract class CRM_Utils_Hook {
     &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6,
     $fnSuffix
   ) {
-    $count = is_array($names) ? count($names) : $names;
-    return $this->invokeViaUF($count, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $fnSuffix);
+    if (is_array($names) && !defined('CIVICRM_FORCE_LEGACY_HOOK')) {
+      $event = \Civi\Core\Event\GenericHookEvent::createOrdered(
+        $names,
+        array(&$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6)
+      );
+      \Civi::dispatcher()->dispatch('hook_' . $fnSuffix, $event);
+      return $event->getReturnValues();
+    }
+    else {
+      $count = is_array($names) ? count($names) : $names;
+      return $this->invokeViaUF($count, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $fnSuffix);
+    }
   }
 
   /**