Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh entity list after updating custom group (self_hook_*) #22868

Merged
merged 2 commits into from
Mar 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CRM/Core/BAO/CustomGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
32 changes: 32 additions & 0 deletions tests/phpunit/api/v4/Action/CustomValueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}

}