Skip to content

Commit

Permalink
SearchKit - Add links to view/edit/delete relationships
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed Jul 17, 2021
1 parent 396b4a9 commit 7e22446
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions Civi/Api4/RelationshipCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static function getFields($checkPermissions = TRUE) {
*/
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')],
Expand Down
2 changes: 1 addition & 1 deletion ext/search_kit/Civi/Search/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static function getStyles():array {
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([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,22 @@
// 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 + '.');
link.join = join.alias;
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) {
Expand Down

0 comments on commit 7e22446

Please sign in to comment.