From e8854d685ec44bd959c31cb03d2c962eb7ad4b55 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 18 Feb 2021 09:16:16 -0500 Subject: [PATCH] SearchKit - Add links to view multi-record custom data Ideally custom entities would have a full set of CRUD links, but the form code is a bizarre mess and requires a bunch of extra url params that have to be calcultated when constructing the links. Just getting the VIEW link was difficult because I had to remove the requirement of passing CID & teach the form to look it up. --- CRM/Contact/Page/View/CustomData.php | 24 ++++++++++++++++++------ Civi/Api4/Action/Entity/Get.php | 4 +++- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/CRM/Contact/Page/View/CustomData.php b/CRM/Contact/Page/View/CustomData.php index cc6533bb8b..8e78b9064d 100644 --- a/CRM/Contact/Page/View/CustomData.php +++ b/CRM/Contact/Page/View/CustomData.php @@ -21,7 +21,7 @@ class CRM_Contact_Page_View_CustomData extends CRM_Core_Page { /** - * The id of the object being viewed (note/relationship etc). + * Custom group id. * * @var int */ @@ -40,7 +40,23 @@ class CRM_Contact_Page_View_CustomData extends CRM_Core_Page { * Add a few specific things to view contact. */ public function preProcess() { - $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); + $this->_groupId = CRM_Utils_Request::retrieve('gid', 'Positive', $this, TRUE); + $this->assign('groupId', $this->_groupId); + + $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this); + $this->_recId = CRM_Utils_Request::retrieve('recId', 'Positive', $this); + + // If no cid supplied, look it up + if (!$this->_contactId && $this->_recId) { + $tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_groupId, 'table_name'); + if ($tableName) { + $this->_contactId = CRM_Core_DAO::singleValueQuery("SELECT entity_id FROM `$tableName` WHERE id = %1", [1 => [$this->_recId, 'Integer']]); + } + } + if (!$this->_contactId) { + throw new CRM_Core_Exception(ts('Could not find valid value for %1', [1 => 'cid'])); + } + $this->assign('contactId', $this->_contactId); // check logged in url permission @@ -49,12 +65,8 @@ class CRM_Contact_Page_View_CustomData extends CRM_Core_Page { $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); $this->assign('action', $this->_action); - $this->_groupId = CRM_Utils_Request::retrieve('gid', 'Positive', $this, TRUE); - $this->assign('groupId', $this->_groupId); - $this->_multiRecordDisplay = CRM_Utils_Request::retrieve('multiRecordDisplay', 'String', $this, FALSE); $this->_cgcount = CRM_Utils_Request::retrieve('cgcount', 'Positive', $this, FALSE); - $this->_recId = CRM_Utils_Request::retrieve('recId', 'Positive', $this, FALSE); } /** diff --git a/Civi/Api4/Action/Entity/Get.php b/Civi/Api4/Action/Entity/Get.php index d9aef3655c..0deee772fe 100644 --- a/Civi/Api4/Action/Entity/Get.php +++ b/Civi/Api4/Action/Entity/Get.php @@ -104,7 +104,9 @@ class Get extends \Civi\Api4\Generic\BasicGetAction { 'description' => ts('Custom group for %1', [1 => $baseEntity::getInfo()['title_plural']]), 'searchable' => TRUE, 'type' => ['CustomValue'], - 'paths' => [], + 'paths' => [ + 'view' => "civicrm/contact/view/cd?reset=1&gid={$customEntity['id']}&recId=[id]&multiRecordDisplay=single", + ], 'see' => [ 'https://docs.civicrm.org/user/en/latest/organising-your-data/creating-custom-fields/#multiple-record-fieldsets', '\\Civi\\Api4\\CustomGroup', -- 2.25.1