The action regressed when switching search displays to use the GetLinks api action.
This fixes the filtering & makes it more efficient by passing the filter to the api.
*/
public function getLinksMenu() {
$menu = [];
- $discard = array_flip(['add', 'browse']);
+ $exclude = ['add', 'browse'];
$mainEntity = $this->savedSearch['api_entity'] ?? NULL;
if ($mainEntity && !$this->canAggregate(CoreUtil::getIdFieldName($mainEntity))) {
- foreach (array_diff_key(Display::getEntityLinks($mainEntity, TRUE), $discard) as $link) {
+ foreach (Display::getEntityLinks($mainEntity, TRUE, $exclude) as $link) {
$link['join'] = NULL;
$menu[] = $link;
}
if (!$this->canAggregate($join['alias'] . '.' . CoreUtil::getIdFieldName($join['entity']))) {
foreach (array_filter(array_intersect_key($join, $keys)) as $joinEntity) {
$joinLabel = $this->getJoinLabel($join['alias']);
- foreach (array_diff_key(Display::getEntityLinks($joinEntity, $joinLabel), $discard) as $link) {
+ foreach (Display::getEntityLinks($joinEntity, $joinLabel, $exclude) as $link) {
$link['join'] = $join['alias'];
$menu[] = $link;
}
* @param string|bool $addLabel
* Pass a string to supply a custom label, TRUE to use the default,
* or FALSE to keep the %1 placeholders in the text (used for the admin UI)
+ * @param array|null $excludeActions
* @return array[]
*/
- public static function getEntityLinks(string $entity, $addLabel = FALSE): array {
- $links = (array) civicrm_api4($entity, 'getLinks', [
+ public static function getEntityLinks(string $entity, $addLabel = FALSE, array $excludeActions = NULL): array {
+ $apiParams = [
'checkPermissions' => FALSE,
'entityTitle' => $addLabel,
'select' => ['ui_action', 'entity', 'text', 'icon', 'target'],
- ]);
+ ];
+ if ($excludeActions) {
+ $apiParams['where'][] = ['ui_action', 'NOT IN', $excludeActions];
+ }
+ $links = (array) civicrm_api4($entity, 'getLinks', $apiParams);
$styles = [
'delete' => 'danger',
'add' => 'primary',
$this->assertCount(1, $result[1]['columns'][1]['links']);
$this->assertCount(1, $result[2]['columns'][0]['links']);
$this->assertCount(1, $result[2]['columns'][1]['links']);
+ $this->assertContains('View Group', array_column($result[0]['columns'][2]['links'], 'text'));
+ $this->assertContains('Update Group', array_column($result[0]['columns'][2]['links'], 'text'));
+ $this->assertContains('Delete Group', array_column($result[0]['columns'][2]['links'], 'text'));
+ // Add and browse links should not be shown in rows
+ $this->assertNotContains('Add Group', array_column($result[0]['columns'][2]['links'], 'text'));
+ $this->assertNotContains('Browse Group', array_column($result[0]['columns'][2]['links'], 'text'));
// No contact links in 1st row since the group is empty
$this->assertNotContains('View Contact', array_column($result[0]['columns'][2]['links'], 'text'));
$this->assertNotContains('Delete Contact', array_column($result[0]['columns'][2]['links'], 'text'));
$this->assertContains('Delete Contact', array_column($result[1]['columns'][2]['links'], 'text'));
$this->assertContains('View Contact', array_column($result[2]['columns'][2]['links'], 'text'));
$this->assertContains('Delete Contact', array_column($result[2]['columns'][2]['links'], 'text'));
+ // Add and browse links should not be shown in rows
+ $this->assertNotContains('Add Contact', array_column($result[1]['columns'][2]['links'], 'text'));
+ $this->assertNotContains('Browse Contact', array_column($result[2]['columns'][2]['links'], 'text'));
}
/**