From bd502f5ce4ab287d78b636fe2b549f7b6d045bec Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 16 Feb 2024 16:59:08 +1300 Subject: [PATCH] Comment functions with deprecation/ preferred method notices --- CRM/Core/Form/EntityFormTrait.php | 18 ++++++++++++++++++ CRM/Custom/Form/CustomData.php | 22 +++++++++++++++++----- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/CRM/Core/Form/EntityFormTrait.php b/CRM/Core/Form/EntityFormTrait.php index 3941da88d68c..1bebba3d81c4 100644 --- a/CRM/Core/Form/EntityFormTrait.php +++ b/CRM/Core/Form/EntityFormTrait.php @@ -156,6 +156,24 @@ public function addCustomDataToForm() { if ($this->isSuppressCustomData()) { return TRUE; } + + /* + @todo - this would be the preferred code here to better support + php8.2 & take advantage of code improvements + Note in this example an additional filter (membership_type_id) + is relevant although for most entities it isn't. + if ($this->isSubmitted()) { + // The custom data fields are added to the form by an ajax form. + // However, if they are not present in the element index they will + // not be available from `$this->getSubmittedValue()` in post process. + // We do not have to set defaults or otherwise render - just add to the element index. + $this->addCustomDataFieldsToForm($this->getDefaultEntity(), array_filter([ + 'id' => $this->getEntityId(), + 'membership_type_id' => $this->getSubmittedValue('membership_type_id') + ])); + } + */ + $customisableEntities = CRM_Core_SelectValues::customGroupExtends(); if (isset($customisableEntities[$this->getDefaultEntity()])) { CRM_Custom_Form_CustomData::addToForm($this, $this->getEntitySubTypeId()); diff --git a/CRM/Custom/Form/CustomData.php b/CRM/Custom/Form/CustomData.php index 94b9fb4189df..0f9ebdf12a69 100644 --- a/CRM/Custom/Form/CustomData.php +++ b/CRM/Custom/Form/CustomData.php @@ -23,11 +23,6 @@ class CRM_Custom_Form_CustomData { /** * Generic wrapper to add custom data to a form via a single line in preProcess. * - * $this->getDefaultEntity() must be defined for the form class for this to work. - * - * If the postProcess form cannot use the api & instead uses a BAO function it will need. - * $params['custom'] = CRM_Core_BAO_CustomField::postProcess($submitted, $this->_id, $this->getDefaultEntity()); - * * @param CRM_Core_Form $form * @param null|string $entitySubType values stored in civicrm_custom_group.extends_entity_column_value * e.g Student for contact type @@ -36,6 +31,23 @@ class CRM_Custom_Form_CustomData { * @param null|int $contact_id contact ID associated with the custom data. * * @throws \CRM_Core_Exception + * @deprecated - preferred code now is to add to ensure the tpl loads custom + * data using the ajax template & add code to `buildForm()` like this + * + * ``` + * if ($this->isSubmitted()) { + * $this->addCustomDataFieldsToForm('Membership', array_filter([ + * 'id' => $this->getMembershipID(), + * 'membership_type_id' => $this->getSubmittedValue('membership_type_id') + * ])); + * } + * ``` + * + * $this->getDefaultEntity() must be defined for the form class for this to work. + * + * If the postProcess form cannot use the api & instead uses a BAO function it will need. + * $params['custom'] = CRM_Core_BAO_CustomField::postProcess($submitted, $this->_id, $this->getDefaultEntity()); + * */ public static function addToForm(&$form, $entitySubType = NULL, $subName = NULL, $groupCount = 1, $contact_id = NULL) { $entityName = $form->getDefaultEntity();