From 2fcb4a7fc21db2c9b304d02d1a1412c3658982ed Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sun, 11 Aug 2019 16:28:48 +1000 Subject: [PATCH] dev/core#752 Add cid paramater when loading custom data via backend forms so that hooks can modifiy based on contact_id being viewed Add in handling for cid not being set Fix assign of cid and switch to using javascript if rather than smarty --- CRM/Activity/Form/Activity.php | 3 ++- CRM/Custom/Form/CustomData.php | 4 +++- CRM/Custom/Form/CustomDataByType.php | 8 ++++++++ templates/CRM/common/customData.tpl | 7 +++++-- templates/CRM/common/customDataBlock.tpl | 5 +++-- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/CRM/Activity/Form/Activity.php b/CRM/Activity/Form/Activity.php index dc6718406b..cda77aee1d 100644 --- a/CRM/Activity/Form/Activity.php +++ b/CRM/Activity/Form/Activity.php @@ -483,6 +483,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { } // when custom data is included in this page + $this->assign('cid', $this->_currentlyViewedContactId); if (!empty($_POST['hidden_custom'])) { // We need to set it in the session for the code below to work. // CRM-3014 @@ -666,7 +667,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { $element = &$this->add('select', 'activity_type_id', ts('Activity Type'), ['' => '- ' . ts('select') . ' -'] + $this->_fields['followup_activity_type_id']['attributes'], FALSE, [ - 'onchange' => "CRM.buildCustomData( 'Activity', this.value );", + 'onchange' => "CRM.buildCustomData( 'Activity', this.value, false, false, false, false, false, false, {$this->_currentlyViewedContactId});", 'class' => 'crm-select2 required', ] ); diff --git a/CRM/Custom/Form/CustomData.php b/CRM/Custom/Form/CustomData.php index 42d6a5372a..f508e14138 100644 --- a/CRM/Custom/Form/CustomData.php +++ b/CRM/Custom/Form/CustomData.php @@ -49,10 +49,11 @@ class CRM_Custom_Form_CustomData { * e.g Student for contact type * @param null|string $subName value in civicrm_custom_group.extends_entity_column_id * @param null|int $groupCount number of entities that could have custom data + * @param null|int $contact_id contact ID associated with the custom data. * * @throws \CRM_Core_Exception */ - public static function addToForm(&$form, $subType = NULL, $subName = NULL, $groupCount = 1) { + public static function addToForm(&$form, $subType = NULL, $subName = NULL, $groupCount = 1, $contact_id = NULL) { $entityName = $form->getDefaultEntity(); $entityID = $form->getEntityId(); // FIXME: If the form has been converted to use entityFormTrait then getEntitySubTypeId() will exist. @@ -80,6 +81,7 @@ class CRM_Custom_Form_CustomData { $form->assign('customDataType', $entityName); $form->assign('customDataSubType', $entitySubType); $form->assign('entityID', $entityID); + $form->assign('cid', $contact_id); } /** diff --git a/CRM/Custom/Form/CustomDataByType.php b/CRM/Custom/Form/CustomDataByType.php index c88a29fb16..a2f162d972 100644 --- a/CRM/Custom/Form/CustomDataByType.php +++ b/CRM/Custom/Form/CustomDataByType.php @@ -36,6 +36,13 @@ */ class CRM_Custom_Form_CustomDataByType extends CRM_Core_Form { + /** + * Contact ID associated with the Custom Data + * + * @var int + */ + public $_contactID = NULL; + /** * Preprocess function. */ @@ -46,6 +53,7 @@ class CRM_Custom_Form_CustomDataByType extends CRM_Core_Form { $this->_subName = CRM_Utils_Request::retrieve('subName', 'String'); $this->_groupCount = CRM_Utils_Request::retrieve('cgcount', 'Positive'); $this->_entityId = CRM_Utils_Request::retrieve('entityID', 'Positive'); + $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive'); $this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive'); $this->_onlySubtype = CRM_Utils_Request::retrieve('onlySubtype', 'Boolean'); $this->_action = CRM_Utils_Request::retrieve('action', 'Alphanumeric'); diff --git a/templates/CRM/common/customData.tpl b/templates/CRM/common/customData.tpl index 68208c9995..867013c0d4 100644 --- a/templates/CRM/common/customData.tpl +++ b/templates/CRM/common/customData.tpl @@ -26,7 +26,7 @@ {literal}