*/
public static function pre($op, $objectName, $id, &$params) {
$event = new \Civi\Core\Event\PreEvent($op, $objectName, $id, $params);
- \Civi::service('dispatcher')->dispatch("hook_civicrm_pre", $event);
- \Civi::service('dispatcher')->dispatch("hook_civicrm_pre::$objectName", $event);
- return self::singleton()
- ->invoke(4, $op, $objectName, $id, $params, self::$_nullObject, self::$_nullObject, 'civicrm_pre');
+ \Civi::dispatcher()->dispatch('hook_civicrm_pre', $event);
+ return $event->getReturnValues();
}
/**
*/
public static function post($op, $objectName, $objectId, &$objectRef = NULL) {
$event = new \Civi\Core\Event\PostEvent($op, $objectName, $objectId, $objectRef);
- \Civi::service('dispatcher')->dispatch("hook_civicrm_post", $event);
- \Civi::service('dispatcher')->dispatch("hook_civicrm_post::$objectName", $event);
- return self::singleton()
- ->invoke(4, $op, $objectName, $objectId, $objectRef, self::$_nullObject, self::$_nullObject, 'civicrm_post');
+ \Civi::dispatcher()->dispatch('hook_civicrm_post', $event);
+ return $event->getReturnValues();
}
/**
* Reserved for future use.
*/
public static function unhandledException($exception, $request = NULL) {
- self::singleton()
- ->invoke(2, $exception, $request, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_unhandled_exception');
- // == 4.4 ==
- // $event = new stdClass();
- // $event->exception = $exception;
- // CRM_Core_LegacyErrorHandler::handleException($event);
-
- // == 4.5+ ==
$event = new \Civi\Core\Event\UnhandledExceptionEvent($exception, self::$_nullObject);
- \Civi::service('dispatcher')->dispatch("hook_civicrm_unhandled_exception", $event);
+ \Civi::dispatcher()->dispatch('hook_civicrm_unhandled_exception', $event);
}
/**
*/
public static function caseChange(\Civi\CCase\Analyzer $analyzer) {
$event = new \Civi\CCase\Event\CaseChangeEvent($analyzer);
- \Civi::service('dispatcher')->dispatch("hook_civicrm_caseChange", $event);
-
- self::singleton()->invoke(1, $analyzer,
- self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
- 'civicrm_caseChange'
- );
+ \Civi::dispatcher()->dispatch('hook_civicrm_caseChange', $event);
}
/**
*/
namespace Civi\CCase\Event;
+use Civi\Core\Event\GenericHookEvent;
/**
* Class CaseChangeEvent
* @package Civi\API\Event
*/
-class CaseChangeEvent extends \Symfony\Component\EventDispatcher\Event {
+class CaseChangeEvent extends GenericHookEvent {
/**
* @var \Civi\CCase\Analyzer
*/
$this->analyzer = $analyzer;
}
+ /**
+ * @inheritDoc
+ */
+ public function getHookValues() {
+ return array($this->analyzer);
+ }
+
}
$dispatcher = new CiviEventDispatcher($container);
$dispatcher->addListener(SystemInstallEvent::EVENT_NAME, array('\Civi\Core\InstallationCanary', 'check'));
$dispatcher->addListener(SystemInstallEvent::EVENT_NAME, array('\Civi\Core\DatabaseInitializer', 'initialize'));
+ $dispatcher->addListener('hook_civicrm_pre', array('\Civi\Core\Event\PreEvent', 'dispatchSubevent'), 100);
+ $dispatcher->addListener('hook_civicrm_post', array('\Civi\Core\Event\PostEvent', 'dispatchSubevent'), 100);
$dispatcher->addListener('hook_civicrm_post::Activity', array('\Civi\CCase\Events', 'fireCaseChange'));
$dispatcher->addListener('hook_civicrm_post::Case', array('\Civi\CCase\Events', 'fireCaseChange'));
$dispatcher->addListener('hook_civicrm_caseChange', array('\Civi\CCase\Events', 'delegateToXmlListeners'));
$dispatcher->addListener('hook_civicrm_unhandled_exception', array(
'CRM_Core_LegacyErrorHandler',
'handleException',
- ));
+ ), -200);
$dispatcher->addListener(\Civi\ActionSchedule\Events::MAPPINGS, array('CRM_Activity_ActionMapping', 'onRegisterActionMappings'));
$dispatcher->addListener(\Civi\ActionSchedule\Events::MAPPINGS, array('CRM_Contact_ActionMapping', 'onRegisterActionMappings'));
$dispatcher->addListener(\Civi\ActionSchedule\Events::MAPPINGS, array('CRM_Contribute_ActionMapping_ByPage', 'onRegisterActionMappings'));
* Class AuthorizeEvent
* @package Civi\API\Event
*/
-class PostEvent extends \Symfony\Component\EventDispatcher\Event {
+class PostEvent extends GenericHookEvent {
+
+ /**
+ * This adapter automatically emits a narrower event.
+ *
+ * For example, `hook_civicrm_pre(Contact, ...)` will also dispatch `hook_civicrm_pre::Contact`.
+ *
+ * @param \Civi\Core\Event\PostEvent $event
+ */
+ public static function dispatchSubevent(PostEvent $event) {
+ \Civi::service('dispatcher')->dispatch("hook_civicrm_post::" . $event->entity, $event);
+ }
/**
* @var string 'create'|'edit'|'delete' etc
* @param $id
* @param $object
*/
- public function __construct($action, $entity, $id, $object) {
+ public function __construct($action, $entity, $id, &$object) {
$this->action = $action;
$this->entity = $entity;
$this->id = $id;
- $this->object = $object;
+ $this->object = &$object;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getHookValues() {
+ return array($this->action, $this->entity, $this->id, &$this->object);
}
}
* Class AuthorizeEvent
* @package Civi\API\Event
*/
-class PreEvent extends \Symfony\Component\EventDispatcher\Event {
+class PreEvent extends GenericHookEvent {
+
+ /**
+ * This adapter automatically emits a narrower event.
+ *
+ * For example, `hook_civicrm_pre(Contact, ...)` will also dispatch `hook_civicrm_pre::Contact`.
+ *
+ * @param \Civi\Core\Event\PreEvent $event
+ */
+ public static function dispatchSubevent(PreEvent $event) {
+ \Civi::service('dispatcher')->dispatch("hook_civicrm_pre::" . $event->entity, $event);
+ }
/**
* @var string 'create'|'edit'|'delete' etc
* @param $id
* @param $params
*/
- public function __construct($action, $entity, $id, $params) {
+ public function __construct($action, $entity, $id, &$params) {
$this->action = $action;
$this->entity = $entity;
$this->id = $id;
- $this->params = $params;
+ $this->params = &$params;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getHookValues() {
+ return array($this->action, $this->entity, $this->id, &$this->params);
}
}
namespace Civi\Core\Event;
/**
- * Class AuthorizeEvent
+ * Class UnhandledExceptionEvent
* @package Civi\API\Event
*/
-class UnhandledExceptionEvent extends \Symfony\Component\EventDispatcher\Event {
+class UnhandledExceptionEvent extends GenericHookEvent {
/**
* @var \Exception
$this->exception = $e;
}
+ /**
+ * @inheritDoc
+ */
+ public function getHookValues() {
+ return array($this->exception, $this->request);
+ }
+
}