(REF) RecurringEntity BAO - Switch EventSubscriberInterface
authorTim Otten <totten@civicrm.org>
Wed, 26 May 2021 20:53:54 +0000 (13:53 -0700)
committerTim Otten <totten@civicrm.org>
Wed, 26 May 2021 23:52:24 +0000 (16:52 -0700)
This is just an example of doing declarative event-registration from a BAO.

CRM/Core/BAO/RecurringEntity.php
Civi/Core/Container.php

index fceb1237b154f3e87b3518d2b1ff09c01cc7bf75..750959d45b3ffec4d715b34260f4b8bb1034cdae 100644 (file)
@@ -20,7 +20,7 @@ use When\When;
 /**
  * Class CRM_Core_BAO_RecurringEntity.
  */
-class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
+class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity implements \Symfony\Component\EventDispatcher\EventSubscriberInterface {
 
   const RUNNING = 1;
   public $schedule = [];
@@ -115,6 +115,14 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
   const MODE_NEXT_ALL_ENTITY = 2;
   const MODE_ALL_ENTITY_IN_SERIES = 3;
 
+  public static function getSubscribedEvents() {
+    return [
+      'civi.dao.postInsert' => 'triggerInsert',
+      'civi.dao.postUpdate' => 'triggerUpdate',
+      'civi.dao.postDelete' => 'triggerDelete',
+    ];
+  }
+
   /**
    * Getter for status.
    *
index 62f18794078e343db23fe68f3abaa104fb6bd68b..e6d1cff3b32285fe9c3ed510e1c9a93bfc8359f7 100644 (file)
@@ -400,9 +400,6 @@ class Container {
     $dispatcher->addListener('hook_civicrm_permissionList', ['CRM_Core_Permission_List', 'findCiviPermissions'], 950);
     $dispatcher->addListener('hook_civicrm_permissionList', ['CRM_Core_Permission_List', 'findCmsPermissions'], 925);
 
-    $dispatcher->addListener('civi.dao.postInsert', ['\CRM_Core_BAO_RecurringEntity', 'triggerInsert']);
-    $dispatcher->addListener('civi.dao.postUpdate', ['\CRM_Core_BAO_RecurringEntity', 'triggerUpdate']);
-    $dispatcher->addListener('civi.dao.postDelete', ['\CRM_Core_BAO_RecurringEntity', 'triggerDelete']);
     $dispatcher->addListener('hook_civicrm_postSave_civicrm_domain', ['\CRM_Core_BAO_Domain', 'onPostSave']);
     $dispatcher->addListener('hook_civicrm_unhandled_exception', [
       'CRM_Core_LegacyErrorHandler',