Refresh entity list after updating custom group (self_hook_*)
authorTim Otten <totten@civicrm.org>
Wed, 2 Mar 2022 03:02:22 +0000 (19:02 -0800)
committerTim Otten <totten@civicrm.org>
Wed, 2 Mar 2022 03:11:03 +0000 (19:11 -0800)
Overview
----------------------------------------

The CustomGroups are used to generate virtual entities (if they set `is_multiple`). Toggling `is_multiple`
should cause the virtual entity to be added or removed.

Reproduction steps
----------------------------------------

1. Create a custom data group. Leave default `is_multiple=0`.
2. View "API Explorer". Look for the virtual entity. (It's not there. Properly so.)
3. Edit custom data group. Change to `is_multiple=1`.
4. Reload "API Explorer". Look for the virtual entity.

Before
----------------------------------------

The entity does not appear. You have to do a system-flush.

After
----------------------------------------

The entity does appear.

CRM/Core/BAO/CustomGroup.php

index c00e866270eda0c0f01bb3146d9e2276277249c1..e5dbb35f718b5ec88621bdb87f6e0511c650ae1f 100644 (file)
 /**
  * Business object for managing custom data groups.
  */
-class CRM_Core_BAO_CustomGroup extends CRM_Core_DAO_CustomGroup {
+class CRM_Core_BAO_CustomGroup extends CRM_Core_DAO_CustomGroup implements \Civi\Core\HookInterface {
+
+  /**
+   * @param \Civi\Core\Event\PostEvent $e
+   * @see CRM_Utils_Hook::post()
+   */
+  public static function self_hook_civicrm_post(\Civi\Core\Event\PostEvent $e): void {
+    Civi::cache('metadata')->flush();
+  }
 
   /**
    * Takes an associative array and creates a custom group object.