Skip to content

Commit

Permalink
Merge pull request #15231 from pradpnayak/entityrefHook
Browse files Browse the repository at this point in the history
Updated entityRefFilters hook to support alter form create links
  • Loading branch information
colemanw authored Sep 7, 2019
2 parents 8d6badf + 7022db9 commit 65ac066
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CRM/Core/Resources.php
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ public static function getEntityRefMetadata() {
}
}

CRM_Utils_Hook::entityRefFilters($data['filters']);
CRM_Utils_Hook::entityRefFilters($data['filters'], $data['links']);

return $data;
}
Expand Down
5 changes: 3 additions & 2 deletions CRM/Utils/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -2498,9 +2498,10 @@ public static function coreResourceList(&$list, $region) {
* @see CRM_Core_Resources::entityRefFilters
*
* @param array $filters
* @param array $links
*/
public static function entityRefFilters(&$filters) {
self::singleton()->invoke(['filters'], $filters, self::$_nullObject, self::$_nullObject,
public static function entityRefFilters(&$filters, &$links = NULL) {
self::singleton()->invoke(['filters', 'links'], $filters, $links, self::$_nullObject,
self::$_nullObject, self::$_nullObject, self::$_nullObject,
'civicrm_entityRefFilters'
);
Expand Down
24 changes: 24 additions & 0 deletions tests/phpunit/CRM/Core/ResourcesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,4 +432,28 @@ public function testIsFullyFormedUrl($url, $expected) {
$this->assertEquals($expected, CRM_Core_Resources::isFullyFormedUrl($url));
}

/**
* Test for hook_civicrm_entityRefFilters().
*
*/
public function testEntityRefFiltersHook() {
CRM_Utils_Hook_UnitTests::singleton()->setHook('civicrm_entityRefFilters', [$this, 'entityRefFilters']);
$data = CRM_Core_Resources::getEntityRefMetadata();
$this->assertEquals(count($data['links']['Contact']), 4);
$this->assertEquals(!empty($data['links']['Contact']['new_staff']), TRUE);
}

/**
* @param array $filters
* @param array $links
*/
public function entityRefFilters(&$filters, &$links) {
$links['Contact']['new_staff'] = [
'label' => ts('New Staff'),
'url' => '/civicrm/profile/create&reset=1&context=dialog&gid=5',
'type' => 'Individual',
'icon' => 'fa-user',
];
}

}

0 comments on commit 65ac066

Please sign in to comment.