From 17dae666da4a8f1252a6e52a60b112def1656e85 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 31 Aug 2023 08:59:57 +1200 Subject: [PATCH] Copy locationBuildForm function back to only class that calls it --- CRM/Contact/Form/Contact.php | 63 ++++++++++++++++++++++++++++++++++- CRM/Contact/Form/Location.php | 3 ++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/CRM/Contact/Form/Contact.php b/CRM/Contact/Form/Contact.php index 856877a178..397236dc83 100644 --- a/CRM/Contact/Form/Contact.php +++ b/CRM/Contact/Form/Contact.php @@ -819,7 +819,7 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form { // build location blocks. CRM_Contact_Form_Edit_Lock::buildQuickForm($this); - CRM_Contact_Form_Location::buildQuickForm($this); + $this->buildLocationForm(); // add attachment $this->addField('image_URL', ['maxlength' => '255', 'label' => ts('Browse/Upload Image'), 'accept' => 'image/png, image/jpeg, image/gif']); @@ -883,6 +883,67 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form { $this->addButtons($buttons); } + private function buildLocationForm(): void { + // required for subsequent AJAX requests. + $ajaxRequestBlocks = []; + $generateAjaxRequest = 0; + + //build 1 instance of all blocks, without using ajax ... + foreach ($this->_blocks as $blockName => $label) { + $name = strtolower($blockName); + + $instances = [1]; + if (!empty($_POST[$name]) && is_array($_POST[$name])) { + $instances = array_keys($_POST[$name]); + } + elseif (!empty($this->_values[$name]) && is_array($this->_values[$name])) { + $instances = array_keys($this->_values[$name]); + } + + foreach ($instances as $instance) { + if ($instance == 1) { + $this->assign('addBlock', FALSE); + $this->assign('blockId', $instance); + } + else { + //we are going to build other block instances w/ AJAX + $generateAjaxRequest++; + $ajaxRequestBlocks[$blockName][$instance] = TRUE; + } + switch ($blockName) { + case 'Email': + // setDefaults uses this to tell which instance + $this->set('Email_Block_Count', $instance); + CRM_Contact_Form_Edit_Email::buildQuickForm($this, $instance); + // Only display the signature fields if this contact has a CMS account + // because they can only send email if they have access to the CRM + $ufID = $this->_contactId && CRM_Core_BAO_UFMatch::getUFId($this->_contactId); + $this->assign('isAddSignatureFields', (bool) $ufID); + if ($ufID) { + $this->add('textarea', "email[$instance][signature_text]", ts('Signature (Text)'), + ['rows' => 2, 'cols' => 40] + ); + $this->add('wysiwyg', "email[$instance][signature_html]", ts('Signature (HTML)'), + ['rows' => 2, 'cols' => 40] + ); + } + break; + + default: + // @todo This pattern actually adds complexity compared to filling out a switch statement + // for the limited number of blocks - as we also have to receive the block count + $this->set($blockName . '_Block_Count', $instance); + $formName = 'CRM_Contact_Form_Edit_' . $blockName; + $formName::buildQuickForm($this); + } + } + } + + //assign to generate AJAX request for building extra blocks. + $this->assign('generateAjaxRequest', $generateAjaxRequest); + $this->assign('ajaxRequestBlocks', $ajaxRequestBlocks); + } + /** * Form submission of new/edit contact is processed. */ diff --git a/CRM/Contact/Form/Location.php b/CRM/Contact/Form/Location.php index 8040a045f5..206e2e5abc 100644 --- a/CRM/Contact/Form/Location.php +++ b/CRM/Contact/Form/Location.php @@ -13,12 +13,15 @@ * * @package CRM * @copyright CiviCRM LLC https://civicrm.org/licensing + * + * @deprecated in CiviCRM 5.66, will be removed around CiviCRM 5.76. */ class CRM_Contact_Form_Location { /** * Build the form object. * + * @deprecated in CiviCRM 5.66, will be removed around CiviCRM 5.76. * @param CRM_Core_Form $form */ public static function buildQuickForm(&$form) { -- 2.25.1