* @throws \CRM_Core_Exception
*/
public function preProcess() {
- $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']);
- }
- $this->assign('contactID', $this->_contactID);
- CRM_Core_Resources::singleton()->addVars('coreForm', ['contact_id' => (int) $this->_contactID]);
+ $this->assignContactID();
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add');
$this->_mode = empty($this->_mode) ? CRM_Utils_Request::retrieve('mode', 'Alphanumeric', $this) : $this->_mode;
$this->assign('isBackOffice', $this->isBackOffice);
$this->assignPaymentRelatedVariables();
}
+ /**
+ * 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;
+ }
+
/**
* @param int $id
*/
$fields["email-{$this->_bltID}"] = 1;
}
- list($hasBillingField, $addressParams) = CRM_Contribute_BAO_Contribution::getPaymentProcessorReadyAddressParams($this->_params, $this->_bltID);
+ [$hasBillingField, $addressParams] = CRM_Contribute_BAO_Contribution::getPaymentProcessorReadyAddressParams($this->_params, $this->_bltID);
$fields = $this->formatParamsForPaymentProcessor($fields);
if ($hasBillingField) {
}
protected function assignContactEmailDetails() {
- if ($this->_contactID) {
- list($this->userDisplayName, $this->userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID);
+ if ($this->getContactID()) {
+ [$this->userDisplayName, $this->userEmail] = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->getContactID());
if (empty($this->userDisplayName)) {
- $this->userDisplayName = civicrm_api3('contact', 'getvalue', ['id' => $this->_contactID, 'return' => 'display_name']);
+ $this->userDisplayName = civicrm_api3('contact', 'getvalue', ['id' => $this->getContactID(), 'return' => 'display_name']);
}
$this->assign('displayName', $this->userDisplayName);
}
}
+ protected function assignContactID(): void {
+ $this->assign('contactID', $this->getContactID());
+ CRM_Core_Resources::singleton()
+ ->addVars('coreForm', ['contact_id' => (int) $this->getContactID()]);
+ }
+
}
$this->assign('feeBlockPaid', FALSE);
// @todo eliminate this duplication.
- $this->_contactId = $this->_contactID;
+ $this->_contactId = $this->getContactID();
$this->_eID = CRM_Utils_Request::retrieve('eid', 'Positive', $this);
$this->_context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this);
$this->assign('context', $this->_context);
// don't show transaction id in batch update mode
$path = CRM_Utils_System::currentPath();
$form->assign('showTransactionId', FALSE);
- if ($path != 'civicrm/contact/search/basic') {
+ if ($path !== 'civicrm/contact/search/basic') {
$form->add('text', 'trxn_id', ts('Transaction ID'));
$form->addRule('trxn_id', ts('Transaction ID already exists in Database.'),
'objectExists', ['CRM_Contribute_DAO_Contribution', $form->_eventId, 'trxn_id']
}
$contribParams['is_test'] = 0;
- if ($form->_action & CRM_Core_Action::PREVIEW || ($params['mode'] ?? NULL) == 'test') {
+ if ($form->_action & CRM_Core_Action::PREVIEW || ($params['mode'] ?? NULL) === 'test') {
$contribParams['is_test'] = 1;
}
*/
protected function getParticipantValue($fieldName) {
if (!$this->participantRecord) {
- $this->participantRecord = civicrm_api3('Participant', 'getsingle', ['id' => $this->_id]);
+ $this->participantRecord = civicrm_api3('Participant', 'getsingle', ['id' => $this->getParticipantID()]);
}
return $this->participantRecord[$fieldName] ?? $this->participantRecord['participant_' . $fieldName];
}