From 0b82cb6e484a7b7d387f7197e48d28693a6c0790 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Sat, 16 Sep 2023 11:35:35 +1200 Subject: [PATCH] Remove undefined property userName This is causing issues on a bunch of classes - but in fact is only used on the ContributionForm --- CRM/Contribute/Form/AbstractEditPayment.php | 2 +- CRM/Contribute/Form/AdditionalPayment.php | 4 +- CRM/Contribute/Form/Contribution.php | 43 ++++++++++++--------- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/CRM/Contribute/Form/AbstractEditPayment.php b/CRM/Contribute/Form/AbstractEditPayment.php index b9ff55e16988..442b056c293c 100644 --- a/CRM/Contribute/Form/AbstractEditPayment.php +++ b/CRM/Contribute/Form/AbstractEditPayment.php @@ -673,7 +673,7 @@ protected function assignPaymentInfoBlock() { protected function assignContactEmailDetails() { if ($this->getContactID()) { - [$displayName, $this->userEmail] = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->getContactID()); + [$displayName] = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->getContactID()); if (!$displayName) { $displayName = civicrm_api3('contact', 'getvalue', ['id' => $this->getContactID(), 'return' => 'display_name']); } diff --git a/CRM/Contribute/Form/AdditionalPayment.php b/CRM/Contribute/Form/AdditionalPayment.php index de5821dc04f3..259fc2f89e3a 100644 --- a/CRM/Contribute/Form/AdditionalPayment.php +++ b/CRM/Contribute/Form/AdditionalPayment.php @@ -369,9 +369,7 @@ public function processCreditCard() { // we need to retrieve email address if ($this->_context === 'standalone' && !empty($this->_params['is_email_receipt'])) { - list($displayName, - $this->userEmail - ) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactId); + [$displayName] = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactId); $this->assign('displayName', $displayName); } diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 8065dc28bc3a..6e2ea4ff0653 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -17,6 +17,8 @@ * This class generates form components for processing a contribution. */ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditPayment { + use CRM_Contact_Form_ContactFormTrait; + /** * The id of the contribution that we are processing. * @@ -146,11 +148,6 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP * @var array */ public $_paymentFields = []; - /** - * Logged in user's email. - * @var string - */ - public $userEmail; /** * Price set ID. @@ -165,13 +162,6 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP */ public $_priceSet; - /** - * User display name - * - * @var string - */ - public $userDisplayName; - /** * Status message to be shown to the user. * @@ -504,7 +494,6 @@ public function setDefaultValues() { } } - $this->assign('email', $this->userEmail); $this->assign('is_pay_later', !empty($defaults['is_pay_later'])); $this->assign('contribution_status_id', CRM_Utils_Array::value('contribution_status_id', $defaults)); @@ -704,8 +693,8 @@ public function buildQuickForm() { //need to assign custom data type and subtype to the template $this->assign('customDataType', 'Contribution'); $this->assign('customDataSubType', $this->getFinancialTypeID()); - $this->assign('entityID', $this->_id); - + $this->assign('entityID', $this->getContributionID()); + $this->assign('email', $this->getContactValue('email_primary.email')); $contactField = $this->addEntityRef('contact_id', ts('Contributor'), ['create' => TRUE, 'api' => ['extra' => ['email']]], TRUE); if ($this->_context !== 'standalone') { $contactField->freeze(); @@ -1128,7 +1117,7 @@ protected function processCreditCard($submittedValues, $lineItem, $contactID) { $now = date('YmdHis'); - $this->_contributorEmail = $this->userEmail; + $this->_contributorEmail = $this->getContactValue('email_primary.email'); $this->_contributorContactID = $contactID; $this->processBillingAddress(); if (!empty($params['source'])) { @@ -1178,7 +1167,7 @@ protected function processCreditCard($submittedValues, $lineItem, $contactID) { $paymentParams['contributionPageID'] = NULL; if (!empty($this->_params['is_email_receipt'])) { - $paymentParams['email'] = $this->userEmail; + $paymentParams['email'] = $this->getContactValue('email_primary.email'); $paymentParams['is_email_receipt'] = 1; } else { @@ -2045,7 +2034,7 @@ protected function getFinancialTypeID() { public function setUserContext(): void { $session = CRM_Core_Session::singleton(); $buttonName = $this->controller->getButtonName(); - if ($this->_context == 'standalone') { + if ($this->_context === 'standalone') { if ($buttonName == $this->getButtonName('upload', 'new')) { $session->replaceUserContext(CRM_Utils_System::url('civicrm/contribute/add', 'reset=1&action=add&context=standalone' @@ -2208,4 +2197,22 @@ private function assignPremiumProduct($id): void { } } + /** + * Get the contact ID in use. + * + * Ideally override this as appropriate to the form. + * + * @noinspection PhpUnhandledExceptionInspection + * @noinspection PhpDocSignatureIsNotCompleteInspection + */ + public function getContactID(): ?int { + if ($this->_contactID === NULL) { + $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this); + if (empty($this->_contactID) && !empty($this->_id) && $this->entity) { + $this->_contactID = civicrm_api3($this->entity, 'getvalue', ['id' => $this->_id, 'return' => 'contact_id']); + } + } + return $this->_contactID ? (int) $this->_contactID : NULL; + } + }