From: Eileen McNaughton Date: Wed, 30 Aug 2023 22:15:15 +0000 (+1200) Subject: Replace another badly named undeclared property X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=b83d1d71751e4f445a524c4c4a38972a54e45121;p=civicrm-core.git Replace another badly named undeclared property --- diff --git a/CRM/Contact/Form/Contact.php b/CRM/Contact/Form/Contact.php index 397236dc83..85c57cb926 100644 --- a/CRM/Contact/Form/Contact.php +++ b/CRM/Contact/Form/Contact.php @@ -375,18 +375,17 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form { } private function preProcessLocation() { - $this->_addBlockName = CRM_Utils_Request::retrieve('block', 'String'); + $blockName = CRM_Utils_Request::retrieve('block', 'String'); $additionalblockCount = CRM_Utils_Request::retrieve('count', 'Positive'); $this->assign('addBlock', FALSE); - if ($this->_addBlockName && $additionalblockCount) { + if ($blockName && $additionalblockCount) { $this->assign('addBlock', TRUE); - $this->assign('blockName', $this->_addBlockName); + $this->assign('blockName', $blockName); $this->assign('blockId', $additionalblockCount); - $this->set($this->_addBlockName . '_Block_Count', $additionalblockCount); + $this->set($blockName . '_Block_Count', $additionalblockCount); } - $this->assign('blocks', $this->_blocks); $this->assign('className', 'CRM_Contact_Form_Contact'); // get address sequence. @@ -560,7 +559,7 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form { */ public function addRules() { // skip adding formRules when custom data is build - if ($this->_addBlockName || ($this->_action & CRM_Core_Action::DELETE)) { + if ($this->isAjaxMode() || ($this->_action & CRM_Core_Action::DELETE)) { return; } @@ -580,6 +579,38 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form { } } + /** + * Is the form being run in an ajax overload way. + * + * Overloading of existing forms to return ajax forms is an anti-pattern. We + * have removed it in some places (eg, the Payment_Form) & added separate paths. + * + * If someone does separate this out, care needs to be taken to ensure that fields added in the ajax mode + * are also added to the parent form, when separating them. ie it is important to check the + * ajax-loaded fields are in the forms values retrieved from quick form as + * quick form will filter out POST values that have not been added to the + * quick form object.. + * + * @return bool + */ + public function isAjaxMode(): bool { + return (bool) $this->getAjaxBlockName(); + } + + /** + * Get the name of any overload block being used. + * + * This would either be 'CustomData' or a location entity + * (Phone, Address, Email, etc). + * + * @return string + * @noinspection PhpDocMissingThrowsInspection + * @noinspection PhpUnhandledExceptionInspection + */ + public function getAjaxBlockName(): string { + return (string) (CRM_Utils_Request::retrieve('type', 'String') ? 'CustomData' : CRM_Utils_Request::retrieve('block', 'String')); + } + /** * Global validation rules for the form. * @@ -741,8 +772,8 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form { */ public function buildQuickForm() { //load form for child blocks - if ($this->_addBlockName) { - $className = 'CRM_Contact_Form_Edit_' . $this->_addBlockName; + if ($this->isAjaxMode()) { + $className = 'CRM_Contact_Form_Edit_' . $this->getAjaxBlockName(); return $className::buildQuickForm($this); } diff --git a/CRM/Contact/Form/Edit/CustomData.php b/CRM/Contact/Form/Edit/CustomData.php index 4e48301453..9593b39278 100644 --- a/CRM/Contact/Form/Edit/CustomData.php +++ b/CRM/Contact/Form/Edit/CustomData.php @@ -31,9 +31,8 @@ class CRM_Contact_Form_Edit_CustomData { $customDataType = CRM_Utils_Request::retrieve('type', 'String'); if ($customDataType) { - $form->_addBlockName = 'CustomData'; - $form->assign("addBlock", TRUE); - $form->assign("blockName", $form->_addBlockName); + $form->assign('addBlock', TRUE); + $form->assign('blockName', 'CustomData'); } CRM_Custom_Form_CustomData::preProcess($form, NULL, NULL, NULL,