* 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.
*
* @var array
*/
public $_paymentFields = [];
- /**
- * Logged in user's email.
- * @var string
- */
- public $userEmail;
/**
* Price set ID.
*/
public $_priceSet;
- /**
- * User display name
- *
- * @var string
- */
- public $userDisplayName;
-
/**
* Status message to be shown to the user.
*
}
}
- $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));
//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();
$now = date('YmdHis');
- $this->_contributorEmail = $this->userEmail;
+ $this->_contributorEmail = $this->getContactValue('email_primary.email');
$this->_contributorContactID = $contactID;
$this->processBillingAddress();
if (!empty($params['source'])) {
$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 {
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'
}
}
+ /**
+ * 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;
+ }
+
}