From 9f1073d2900ec3270fb8f717afcb50842451bf50 Mon Sep 17 00:00:00 2001 From: "Matthew Wire (MJW Consulting)" Date: Tue, 18 Dec 2018 10:01:49 +0000 Subject: [PATCH] Support customdata subtype on entityform (for activity/relationship types) --- CRM/Core/Form/EntityFormTrait.php | 22 ++++++++++++++++++++++ CRM/Custom/Form/CustomData.php | 5 +++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/CRM/Core/Form/EntityFormTrait.php b/CRM/Core/Form/EntityFormTrait.php index 2f1bdefb0d..a1133f5dfe 100644 --- a/CRM/Core/Form/EntityFormTrait.php +++ b/CRM/Core/Form/EntityFormTrait.php @@ -33,6 +33,13 @@ trait CRM_Core_Form_EntityFormTrait { + /** + * The entity subtype ID (eg. for Relationship / Activity) + * + * @var int + */ + protected $_entitySubTypeId; + /** * Get entity fields for the entity to be added to the form. * @@ -66,6 +73,21 @@ trait CRM_Core_Form_EntityFormTrait { public function getEntityId() { return $this->_id; } + + /** + * Get the entity subtype ID being edited + * + * @param $subTypeId + * + * @return int|null + */ + public function getEntitySubTypeId($subTypeId) { + if ($subTypeId) { + return $subTypeId; + } + return $this->_entitySubTypeId; + } + /** * If the custom data is in the submitted data (eg. added via ajax loaded form) add to form. */ diff --git a/CRM/Custom/Form/CustomData.php b/CRM/Custom/Form/CustomData.php index 4c9b3499a8..f4528ceac3 100644 --- a/CRM/Custom/Form/CustomData.php +++ b/CRM/Custom/Form/CustomData.php @@ -55,16 +55,17 @@ class CRM_Custom_Form_CustomData { public static function addToForm(&$form, $subType = NULL, $subName = NULL, $groupCount = 1) { $entityName = $form->getDefaultEntity(); $entityID = $form->getEntityId(); + $entitySubType = $form->getEntitySubTypeId($subType); // when custom data is included in this page if (!empty($_POST['hidden_custom'])) { - self::preProcess($form, $subName, $subType, $groupCount, $entityName, $entityID); + self::preProcess($form, $subName, $entitySubType, $groupCount, $entityName, $entityID); self::buildQuickForm($form); self::setDefaultValues($form); } // need to assign custom data type and subtype to the template $form->assign('customDataType', $entityName); - $form->assign('customDataSubType', $subType); + $form->assign('customDataSubType', $entitySubType); $form->assign('entityID', $entityID); } -- 2.25.1