From ed706f8dbaf5d8812f57bcd251f223b650d31f3c Mon Sep 17 00:00:00 2001 From: "Matthew Wire (MJW Consulting)" Date: Mon, 2 Dec 2019 12:45:57 +0000 Subject: [PATCH] Add function to set entitySubType for entity forms --- CRM/Case/Form/Case.php | 14 -------------- CRM/Core/Form/EntityFormTrait.php | 20 ++++++++++++-------- CRM/Custom/Form/CustomData.php | 13 +++++-------- templates/CRM/Activity/Form/Activity.tpl | 1 - 4 files changed, 17 insertions(+), 31 deletions(-) diff --git a/CRM/Case/Form/Case.php b/CRM/Case/Form/Case.php index 0d43ed1912af..05e832c74454 100644 --- a/CRM/Case/Form/Case.php +++ b/CRM/Case/Form/Case.php @@ -93,20 +93,6 @@ public function getEntityId() { return $this->_caseId; } - /** - * Get the entity subtype ID being edited - * - * @param $subTypeId - * - * @return int|null - */ - public function getEntitySubTypeId($subTypeId) { - if ($subTypeId) { - return $subTypeId; - } - return $this->_caseTypeId; - } - /** * Build the form object. */ diff --git a/CRM/Core/Form/EntityFormTrait.php b/CRM/Core/Form/EntityFormTrait.php index 61b800205de2..15ff60830a79 100644 --- a/CRM/Core/Form/EntityFormTrait.php +++ b/CRM/Core/Form/EntityFormTrait.php @@ -21,7 +21,7 @@ trait CRM_Core_Form_EntityFormTrait { * * @var int */ - protected $_entitySubTypeId; + protected $_entitySubTypeId = NULL; /** * Get entity fields for the entity to be added to the form. @@ -83,17 +83,21 @@ protected function isSuppressCustomData() { /** * Get the entity subtype ID being edited * - * @param $subTypeId - * * @return int|null */ - public function getEntitySubTypeId($subTypeId) { - if ($subTypeId) { - return $subTypeId; - } + public function getEntitySubTypeId() { return $this->_entitySubTypeId; } + /** + * Set the entity subtype ID being edited + * + * @param $subTypeId + */ + public function setEntitySubTypeId($subTypeId) { + $this->_entitySubTypeId = $subTypeId; + } + /** * If the custom data is in the submitted data (eg. added via ajax loaded form) add to form. */ @@ -103,7 +107,7 @@ public function addCustomDataToForm() { } $customisableEntities = CRM_Core_SelectValues::customGroupExtends(); if (isset($customisableEntities[$this->getDefaultEntity()])) { - CRM_Custom_Form_CustomData::addToForm($this); + CRM_Custom_Form_CustomData::addToForm($this, $this->getEntitySubTypeId()); } } diff --git a/CRM/Custom/Form/CustomData.php b/CRM/Custom/Form/CustomData.php index 8bdc0d79ace5..e502c72e15b1 100644 --- a/CRM/Custom/Form/CustomData.php +++ b/CRM/Custom/Form/CustomData.php @@ -29,7 +29,7 @@ class CRM_Custom_Form_CustomData { * $params['custom'] = CRM_Core_BAO_CustomField::postProcess($submitted, $this->_id, $this->getDefaultEntity()); * * @param CRM_Core_Form $form - * @param null|string $subType values stored in civicrm_custom_group.extends_entity_column_value + * @param null|string $entitySubType values stored in civicrm_custom_group.extends_entity_column_value * 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 @@ -37,15 +37,12 @@ class CRM_Custom_Form_CustomData { * * @throws \CRM_Core_Exception */ - public static function addToForm(&$form, $subType = NULL, $subName = NULL, $groupCount = 1, $contact_id = NULL) { + public static function addToForm(&$form, $entitySubType = 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. - // However, if it is only partially converted (ie. we've switched customdata to use CRM_Custom_Form_CustomData) - // it won't, so we check if we have a subtype before calling the function. - $entitySubType = NULL; - if ($subType) { - $entitySubType = $form->getEntitySubTypeId($subType); + // If the form has been converted to use entityFormTrait then getEntitySubTypeId() will exist. + if (method_exists($form, 'getEntitySubTypeId') && empty($entitySubType)) { + $entitySubType = $form->getEntitySubTypeId(); } if ($form->getAction() == CRM_Core_Action::VIEW) { diff --git a/templates/CRM/Activity/Form/Activity.tpl b/templates/CRM/Activity/Form/Activity.tpl index 5b2e22a499a9..a02f93f15f5e 100644 --- a/templates/CRM/Activity/Form/Activity.tpl +++ b/templates/CRM/Activity/Form/Activity.tpl @@ -179,7 +179,6 @@ {if $action eq 4} {include file="CRM/Custom/Page/CustomDataView.tpl"} {else} -
{include file="CRM/common/customDataBlock.tpl"} {/if}