From 936e341d0641059ed807be968975ed8229ea779b Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 15 May 2023 11:28:31 +1200 Subject: [PATCH] Improve fromEmail address handling We don't need to validate the from Email address in the postProcess as the form submit validation expects it to be a supplied value. Fixing this makes testing easier --- CRM/Event/Form/EventFees.php | 1 + CRM/Event/Form/Participant.php | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/CRM/Event/Form/EventFees.php b/CRM/Event/Form/EventFees.php index 2b15c288ce..8031bb5fa8 100644 --- a/CRM/Event/Form/EventFees.php +++ b/CRM/Event/Form/EventFees.php @@ -37,6 +37,7 @@ class CRM_Event_Form_EventFees { $form->_pId = CRM_Utils_Request::retrieve('participantId', 'Positive', $form); $form->_discountId = CRM_Utils_Request::retrieve('discountId', 'Positive', $form); + // @todo - stop setting this, call the function, as appropriate. This is in a weird place. $form->_fromEmails = CRM_Event_BAO_Event::getFromEmailIds($form->_eventId); //CRM-6907 set event specific currency. diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index f019325aba..ab032fcd34 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -200,7 +200,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment * * @var int */ - public $_eventId = NULL; + public $_eventId; /** * Id of payment, if any @@ -785,7 +785,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment * @param $files * @param self $self * - * @return array + * @return array|true * list of errors to be posted back to the form */ public static function formRule($values, $files, $self) { @@ -1547,7 +1547,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment ['onclick' => "showHideByValue('send_receipt','','notice','table-row','radio',false); showHideByValue('send_receipt','','from-email','table-row','radio',false);"] ); - $form->add('select', 'from_email_address', ts('Receipt From'), $form->_fromEmails['from_email_id']); + $form->add('select', 'from_email_address', ts('Receipt From'), $form->getAvailableFromEmails()['from_email_id']); $form->add('textarea', 'receipt_text', ts('Confirmation Message')); @@ -1568,6 +1568,15 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment $form->assign('hasPayment', $form->_paymentId); } + /** + * Get the emails available for the from address. + * + * @return array + */ + protected function getAvailableFromEmails(): array { + return CRM_Event_BAO_Event::getFromEmailIds($this->getEventID()); + } + /** * Extracted code relating to paid events. * @@ -2225,10 +2234,7 @@ INNER JOIN civicrm_price_field_value value ON ( value.id = lineItem.price_field_ // try to send emails only if email id is present // and the do-not-email option is not checked for that contact if ($this->_contributorEmail and !$this->_toDoNotEmail) { - if (array_key_exists($params['from_email_address'], $this->_fromEmails['from_email_id'])) { - $receiptFrom = $params['from_email_address']; - } - $sendTemplateParams['from'] = $receiptFrom; + $sendTemplateParams['from'] = $params['from_email_address']; $sendTemplateParams['toName'] = $this->_contributorDisplayName; $sendTemplateParams['toEmail'] = $this->_contributorEmail; $sendTemplateParams['cc'] = $this->_fromEmails['cc'] ?? NULL; -- 2.25.1