diff --git a/CRM/Core/BAO/CustomGroup.php b/CRM/Core/BAO/CustomGroup.php index c00e866270ed..e5dbb35f718b 100644 --- a/CRM/Core/BAO/CustomGroup.php +++ b/CRM/Core/BAO/CustomGroup.php @@ -18,7 +18,15 @@ /** * 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. diff --git a/tests/phpunit/api/v4/Action/CustomValueTest.php b/tests/phpunit/api/v4/Action/CustomValueTest.php index 337cc3c5903a..f774d3acce8e 100644 --- a/tests/phpunit/api/v4/Action/CustomValueTest.php +++ b/tests/phpunit/api/v4/Action/CustomValueTest.php @@ -263,4 +263,36 @@ public function testCRUD() { $this->assertEquals(0, count($result)); } + /** + * Whenever a CustomGroup toggles the `is_multiple` flag, the entity-list should be updated. + * + * @throws \API_Exception + * @throws \Civi\API\Exception\UnauthorizedException + */ + public function testEntityRefresh() { + $groupName = uniqid('groupc'); + + $this->assertNotContains("Custom_$groupName", Entity::get()->execute()->column('name')); + + CustomGroup::create(FALSE) + ->addValue('title', $groupName) + ->addValue('extends', 'Contact') + ->addValue('is_multiple', FALSE) + ->execute(); + + $this->assertNotContains("Custom_$groupName", Entity::get()->execute()->column('name')); + + CustomGroup::update(FALSE) + ->addWhere('name', '=', $groupName) + ->addValue('is_multiple', TRUE) + ->execute(); + $this->assertContains("Custom_$groupName", Entity::get()->execute()->column('name')); + + CustomGroup::update(FALSE) + ->addWhere('name', '=', $groupName) + ->addValue('is_multiple', FALSE) + ->execute(); + $this->assertNotContains("Custom_$groupName", Entity::get()->execute()->column('name')); + } + }