Skip to content

Commit

Permalink
Merge pull request #27456 from eileenmcnaughton/user_email
Browse files Browse the repository at this point in the history
PHP8.2 Remove undefined property userName
  • Loading branch information
demeritcowboy authored Sep 18, 2023
2 parents 91ac1dc + 0b82cb6 commit 7cb959e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
2 changes: 1 addition & 1 deletion CRM/Contribute/Form/AbstractEditPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
Expand Down
4 changes: 1 addition & 3 deletions CRM/Contribute/Form/AdditionalPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
43 changes: 25 additions & 18 deletions CRM/Contribute/Form/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
Expand All @@ -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.
*
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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'])) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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;
}

}

0 comments on commit 7cb959e

Please sign in to comment.