From 7e224460b24c1d90f0201f7904d3b45648b87f9c Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 16 Jul 2021 20:48:29 -0400 Subject: [PATCH] SearchKit - Add links to view/edit/delete relationships --- Civi/Api4/RelationshipCache.php | 1 + ext/search_kit/Civi/Search/Admin.php | 2 +- .../crmSearchAdmin/crmSearchAdminDisplay.component.js | 10 +++++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Civi/Api4/RelationshipCache.php b/Civi/Api4/RelationshipCache.php index e0d2713fc9..e967d2373f 100644 --- a/Civi/Api4/RelationshipCache.php +++ b/Civi/Api4/RelationshipCache.php @@ -45,6 +45,7 @@ class RelationshipCache extends Generic\AbstractEntity { */ public static function getInfo() { $info = parent::getInfo(); + $info['bridge_title'] = ts('Relationship'); $info['bridge'] = [ 'near_contact_id' => ['description' => ts('One or more contacts with a relationship to this contact')], 'far_contact_id' => ['description' => ts('One or more contacts with a relationship to this contact')], diff --git a/ext/search_kit/Civi/Search/Admin.php b/ext/search_kit/Civi/Search/Admin.php index 925422d971..901c0a1440 100644 --- a/ext/search_kit/Civi/Search/Admin.php +++ b/ext/search_kit/Civi/Search/Admin.php @@ -82,7 +82,7 @@ class Admin { public static function getSchema() { $schema = []; $entities = \Civi\Api4\Entity::get() - ->addSelect('name', 'title', 'type', 'primary_key', 'title_plural', 'description', 'label_field', 'icon', 'paths', 'dao', 'bridge', 'ui_join_filters', 'searchable') + ->addSelect('name', 'title', 'title_plural', 'bridge_title', 'type', 'primary_key', 'description', 'label_field', 'icon', 'paths', 'dao', 'bridge', 'ui_join_filters', 'searchable') ->addWhere('searchable', '!=', 'none') ->addOrderBy('title_plural') ->setChain([ diff --git a/ext/search_kit/ang/crmSearchAdmin/crmSearchAdminDisplay.component.js b/ext/search_kit/ang/crmSearchAdmin/crmSearchAdminDisplay.component.js index a15f452b67..c53851836c 100644 --- a/ext/search_kit/ang/crmSearchAdmin/crmSearchAdminDisplay.component.js +++ b/ext/search_kit/ang/crmSearchAdmin/crmSearchAdminDisplay.component.js @@ -264,7 +264,8 @@ // Links to explicitly joined entities _.each(ctrl.savedSearch.api_params.join, function(joinClause) { var join = searchMeta.getJoin(joinClause[0]), - joinEntity = searchMeta.getEntity(join.entity); + joinEntity = searchMeta.getEntity(join.entity), + bridgeEntity = _.isString(joinClause[2]) ? searchMeta.getEntity(joinClause[2]) : null; _.each(joinEntity.paths, function(path) { var link = _.cloneDeep(path); link.path = link.path.replace(/\[/g, '[' + join.alias + '.'); @@ -272,6 +273,13 @@ addTitle(link, join.label); links.push(link); }); + _.each(bridgeEntity && bridgeEntity.paths, function(path) { + var link = _.cloneDeep(path); + link.path = link.path.replace(/\[/g, '[' + join.alias + '.'); + link.join = join.alias; + addTitle(link, join.label + (bridgeEntity.bridge_title ? ' ' + bridgeEntity.bridge_title : '')); + links.push(link); + }); }); // Links to implicit joins _.each(ctrl.savedSearch.api_params.select, function(fieldName) { -- 2.25.1