From f1bc38d55e64d9fbf4d54610ac06e990577ff7ff Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 12 Sep 2023 11:49:10 +1200 Subject: [PATCH] Use local variable instead of undefined property for formType --- CRM/Contact/Form/ContactFormTrait.php | 8 +------- CRM/Pledge/Form/Pledge.php | 15 ++++++++------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/CRM/Contact/Form/ContactFormTrait.php b/CRM/Contact/Form/ContactFormTrait.php index 9a7a00ea71..fc66253a72 100644 --- a/CRM/Contact/Form/ContactFormTrait.php +++ b/CRM/Contact/Form/ContactFormTrait.php @@ -28,10 +28,7 @@ trait CRM_Contact_Form_ContactFormTrait { } $id = $this->getContactID(); if ($id) { - // GetContactID may or may not have defined this. - if (!$this->isDefined('Contact')) { - $this->define('Contact', 'Contact', ['id' => $id]); - } + $this->define('Contact', 'Contact', ['id' => $id]); return $this->lookup('Contact', $fieldName); } return NULL; @@ -49,9 +46,6 @@ trait CRM_Contact_Form_ContactFormTrait { */ public function getContactID(): ?int { $id = (int) CRM_Utils_Request::retrieve('cid', 'Positive', $this); - if ($id) { - $this->define('Contact', 'Contact', ['id' => $id]); - } return $id ?: NULL; } diff --git a/CRM/Pledge/Form/Pledge.php b/CRM/Pledge/Form/Pledge.php index 9cbcab3b97..aa454fe586 100644 --- a/CRM/Pledge/Form/Pledge.php +++ b/CRM/Pledge/Form/Pledge.php @@ -90,7 +90,7 @@ class CRM_Pledge_Form_Pledge extends CRM_Core_Form { $params = ['id' => $this->_id]; CRM_Pledge_BAO_Pledge::getValues($params, $this->_values); - $this->_isPending = (CRM_Pledge_BAO_Pledge::pledgeHasFinancialTransactions($this->_id, CRM_Utils_Array::value('status_id', $this->_values))) ? FALSE : TRUE; + $this->_isPending = !CRM_Pledge_BAO_Pledge::pledgeHasFinancialTransactions($this->_id, CRM_Utils_Array::value('status_id', $this->_values)); } // get the pledge frequency units. @@ -100,6 +100,8 @@ class CRM_Pledge_Form_Pledge extends CRM_Core_Form { /** * Set default values for the form. * The default values are retrieved from the database. + * + * @throws \CRM_Core_Exception */ public function setDefaultValues(): array { $defaults = $this->_values; @@ -189,13 +191,12 @@ class CRM_Pledge_Form_Pledge extends CRM_Core_Form { } $contactField = $this->addEntityRef('contact_id', ts('Pledge by'), ['create' => TRUE, 'api' => ['extra' => ['email']]], TRUE); - if ($this->_context !== 'standalone') { + if ($this->getContext() !== 'standalone') { $contactField->freeze(); } $showAdditionalInfo = FALSE; - $this->_formType = $_GET['formType'] ?? NULL; - + $formType = CRM_Utils_Request::retrieveValue('form_type', 'String'); $defaults = []; $paneNames = [ @@ -209,7 +210,7 @@ class CRM_Pledge_Form_Pledge extends CRM_Core_Form { 'id' => $type, ]; // see if we need to include this paneName in the current form - if ($this->_formType == $type || !empty($_POST["hidden_{$type}"]) || + if ($formType == $type || !empty($_POST["hidden_{$type}"]) || !empty($defaults["hidden_{$type}"]) ) { $showAdditionalInfo = TRUE; @@ -222,8 +223,8 @@ class CRM_Pledge_Form_Pledge extends CRM_Core_Form { $this->assign('allPanes', $allPanes); $this->assign('showAdditionalInfo', $showAdditionalInfo); - $this->assign('formType', $this->_formType); - if ($this->_formType) { + $this->assign('formType', $formType); + if ($formType) { return; } -- 2.25.1