From 651a56355559aa312fc3ffd9fa9cce89e866475a Mon Sep 17 00:00:00 2001 From: colemanw Date: Thu, 28 Sep 2023 22:47:18 -0400 Subject: [PATCH] Add icons to relationship permission metadata --- CRM/Contact/DAO/Relationship.php | 12 +++++++++++- CRM/Core/SelectValues.php | 3 +++ .../Spec/Provider/RelationshipCacheSpecProvider.php | 1 + tests/phpunit/api/v4/Entity/RelationshipTest.php | 10 +++++----- xml/schema/Contact/Relationship.xml | 2 ++ 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/CRM/Contact/DAO/Relationship.php b/CRM/Contact/DAO/Relationship.php index 32b8f3e61b..ea5624a36f 100644 --- a/CRM/Contact/DAO/Relationship.php +++ b/CRM/Contact/DAO/Relationship.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Contact/Relationship.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:053ca157abcac8e7f4c8ab55425df5ff) + * (GenCodeChecksum:e6e709da33773d09d7e788d21c64437b) */ /** @@ -423,6 +423,11 @@ class CRM_Contact_DAO_Relationship extends CRM_Core_DAO { ], 'pseudoconstant' => [ 'callback' => 'CRM_Core_SelectValues::getPermissionedRelationshipOptions', + 'suffixes' => [ + 'name', + 'label', + 'icon', + ], ], 'add' => '2.1', ], @@ -449,6 +454,11 @@ class CRM_Contact_DAO_Relationship extends CRM_Core_DAO { ], 'pseudoconstant' => [ 'callback' => 'CRM_Core_SelectValues::getPermissionedRelationshipOptions', + 'suffixes' => [ + 'name', + 'label', + 'icon', + ], ], 'add' => '2.1', ], diff --git a/CRM/Core/SelectValues.php b/CRM/Core/SelectValues.php index 0573b1a8a1..b416d0e7fe 100644 --- a/CRM/Core/SelectValues.php +++ b/CRM/Core/SelectValues.php @@ -1079,16 +1079,19 @@ class CRM_Core_SelectValues { 'id' => CRM_Contact_BAO_Relationship::NONE, 'name' => 'None', 'label' => ts('None'), + 'icon' => NULL, ], [ 'id' => CRM_Contact_BAO_Relationship::VIEW, 'name' => 'View only', 'label' => ts('View only'), + 'icon' => 'fa-eye', ], [ 'id' => CRM_Contact_BAO_Relationship::EDIT, 'name' => 'View and update', 'label' => ts('View and update'), + 'icon' => 'fa-pencil', ], ]; } diff --git a/Civi/Api4/Service/Spec/Provider/RelationshipCacheSpecProvider.php b/Civi/Api4/Service/Spec/Provider/RelationshipCacheSpecProvider.php index 051d7d0753..a7468f2c73 100644 --- a/Civi/Api4/Service/Spec/Provider/RelationshipCacheSpecProvider.php +++ b/Civi/Api4/Service/Spec/Provider/RelationshipCacheSpecProvider.php @@ -61,6 +61,7 @@ class RelationshipCacheSpecProvider extends \Civi\Core\Service\AutoService imple // Fetches the value from the relationship ->setColumnName('relationship_id') ->setDescription($fieldInfo['description']) + ->setSuffixes(['name', 'label', 'icon']) ->setOptionsCallback(['CRM_Core_SelectValues', 'getPermissionedRelationshipOptions']) ->setSqlRenderer([__CLASS__, 'directionalRelationshipField']); $spec->addFieldSpec($field); diff --git a/tests/phpunit/api/v4/Entity/RelationshipTest.php b/tests/phpunit/api/v4/Entity/RelationshipTest.php index 84c4f75f02..2c3be858e5 100644 --- a/tests/phpunit/api/v4/Entity/RelationshipTest.php +++ b/tests/phpunit/api/v4/Entity/RelationshipTest.php @@ -77,15 +77,15 @@ class RelationshipTest extends Api4TestBase implements TransactionalInterface { ->execute()->first(); $cacheRecords = RelationshipCache::get(FALSE) ->addWhere('near_contact_id', 'IN', [$c1, $c2]) - ->addSelect('near_contact_id', 'orientation', 'description', 'relationship_created_date', 'relationship_modified_date', 'permission_near_to_far', 'permission_far_to_near') + ->addSelect('near_contact_id', 'orientation', 'description', 'relationship_created_date', 'relationship_modified_date', 'permission_near_to_far:name', 'permission_far_to_near:name') ->execute()->indexBy('near_contact_id'); $this->assertCount(2, $cacheRecords); $this->assertEquals("Wow, we're related!", $cacheRecords[$c1]['description']); $this->assertEquals("Wow, we're related!", $cacheRecords[$c2]['description']); - $this->assertEquals(1, $cacheRecords[$c1]['permission_near_to_far']); - $this->assertEquals(2, $cacheRecords[$c2]['permission_near_to_far']); - $this->assertEquals(2, $cacheRecords[$c1]['permission_far_to_near']); - $this->assertEquals(1, $cacheRecords[$c2]['permission_far_to_near']); + $this->assertEquals('View and update', $cacheRecords[$c1]['permission_near_to_far:name']); + $this->assertEquals('View only', $cacheRecords[$c2]['permission_near_to_far:name']); + $this->assertEquals('View only', $cacheRecords[$c1]['permission_far_to_near:name']); + $this->assertEquals('View and update', $cacheRecords[$c2]['permission_far_to_near:name']); $this->assertEquals($relationship['created_date'], $cacheRecords[$c1]['relationship_created_date']); $this->assertEquals($relationship['modified_date'], $cacheRecords[$c2]['relationship_modified_date']); } diff --git a/xml/schema/Contact/Relationship.xml b/xml/schema/Contact/Relationship.xml index fd121341d7..d65dd5eb52 100644 --- a/xml/schema/Contact/Relationship.xml +++ b/xml/schema/Contact/Relationship.xml @@ -149,6 +149,7 @@ 2.1 CRM_Core_SelectValues::getPermissionedRelationshipOptions + name,label,icon Radio @@ -164,6 +165,7 @@ 2.1 CRM_Core_SelectValues::getPermissionedRelationshipOptions + name,label,icon Radio -- 2.25.1