From fd901044c9a37663407171df0818f507e1dfc856 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Mon, 26 May 2014 16:57:43 -0700 Subject: [PATCH] CRM_Utils_Hook - Fire Symfony event dispatcher for hook_post and hook_pre. --- CRM/Utils/Hook.php | 6 ++++ Civi/Core/Event/PostEvent.php | 62 +++++++++++++++++++++++++++++++++++ Civi/Core/Event/PreEvent.php | 62 +++++++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+) create mode 100644 Civi/Core/Event/PostEvent.php create mode 100644 Civi/Core/Event/PreEvent.php diff --git a/CRM/Utils/Hook.php b/CRM/Utils/Hook.php index 523b4020b4..f1a431c6f0 100644 --- a/CRM/Utils/Hook.php +++ b/CRM/Utils/Hook.php @@ -259,6 +259,9 @@ abstract class CRM_Utils_Hook { * @return null the return value is ignored */ static function pre($op, $objectName, $id, &$params) { + $event = new \Civi\Core\Event\PreEvent($op, $objectName, $id, $params); + \Civi\Core\Container::singleton()->get('dispatcher')->dispatch("hook_civicrm_pre", $event); + \Civi\Core\Container::singleton()->get('dispatcher')->dispatch("hook_civicrm_pre::$objectName", $event); return self::singleton()->invoke(4, $op, $objectName, $id, $params, self::$_nullObject, self::$_nullObject, 'civicrm_pre'); } @@ -275,6 +278,9 @@ abstract class CRM_Utils_Hook { * @access public */ static function post($op, $objectName, $objectId, &$objectRef) { + $event = new \Civi\Core\Event\PostEvent($op, $objectName, $objectId, $objectRef); + \Civi\Core\Container::singleton()->get('dispatcher')->dispatch("hook_civicrm_post", $event); + \Civi\Core\Container::singleton()->get('dispatcher')->dispatch("hook_civicrm_post::$objectName", $event); return self::singleton()->invoke(4, $op, $objectName, $objectId, $objectRef, self::$_nullObject, self::$_nullObject, 'civicrm_post'); } diff --git a/Civi/Core/Event/PostEvent.php b/Civi/Core/Event/PostEvent.php new file mode 100644 index 0000000000..e2d0093884 --- /dev/null +++ b/Civi/Core/Event/PostEvent.php @@ -0,0 +1,62 @@ +action = $action; + $this->entity = $entity; + $this->id = $id; + $this->object = $object; + } +} diff --git a/Civi/Core/Event/PreEvent.php b/Civi/Core/Event/PreEvent.php new file mode 100644 index 0000000000..6b44ab4b15 --- /dev/null +++ b/Civi/Core/Event/PreEvent.php @@ -0,0 +1,62 @@ +action = $action; + $this->entity = $entity; + $this->id = $id; + $this->params = $params; + } +} -- 2.25.1