From 93a8134f9f62486a0bdf6e20b7651d36d4e10204 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Sun, 26 Sep 2021 16:55:20 +1300 Subject: [PATCH] Remove handling for empty required field From is a required field - remove code to handle it being empty --- CRM/Contact/Form/Task/EmailTrait.php | 18 +++--------------- .../CRM/Contribute/Form/Task/EmailTest.php | 5 +++-- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/CRM/Contact/Form/Task/EmailTrait.php b/CRM/Contact/Form/Task/EmailTrait.php index 058eef3bf7..10054718f5 100644 --- a/CRM/Contact/Form/Task/EmailTrait.php +++ b/CRM/Contact/Form/Task/EmailTrait.php @@ -406,7 +406,7 @@ trait CRM_Contact_Form_Task_EmailTrait { public function submit($formValues): void { $this->saveMessageTemplate($formValues); - $from = $formValues['from_email_address'] ?? NULL; + $from = $formValues['from_email_address']; // dev/core#357 User Emails are keyed by their id so that the Signature is able to be added // If we have had a contact email used here the value returned from the line above will be the // numerical key where as $from for use in the sendEmail in Activity needs to be of format of "To Name" @@ -790,7 +790,7 @@ trait CRM_Contact_Form_Task_EmailTrait { * The subject of the message. * @param $text * @param $html - * @param string|null $from + * @param string $from * @param array|null $attachments * The array of attachments if any. * @param string|null $cc @@ -820,7 +820,7 @@ trait CRM_Contact_Form_Task_EmailTrait { $subject, $text, $html, - $from = NULL, + $from, $attachments = NULL, $cc = NULL, $bcc = NULL, @@ -832,18 +832,6 @@ trait CRM_Contact_Form_Task_EmailTrait { $userID = CRM_Core_Session::getLoggedInContactID(); - [$fromDisplayName, $fromEmail, $fromDoNotEmail] = CRM_Contact_BAO_Contact::getContactDetails($userID); - if (!$fromEmail) { - return [count($contactDetails), 0, count($contactDetails)]; - } - if (!trim($fromDisplayName)) { - $fromDisplayName = $fromEmail; - } - - if (!$from) { - $from = "$fromDisplayName <$fromEmail>"; - } - $contributionDetails = []; if (!empty($contributionIds)) { $contributionDetails = Contribution::get(FALSE) diff --git a/tests/phpunit/CRM/Contribute/Form/Task/EmailTest.php b/tests/phpunit/CRM/Contribute/Form/Task/EmailTest.php index 9ad4974b9c..e3cdc9ffc7 100644 --- a/tests/phpunit/CRM/Contribute/Form/Task/EmailTest.php +++ b/tests/phpunit/CRM/Contribute/Form/Task/EmailTest.php @@ -39,12 +39,12 @@ class CRM_Contribute_Form_Task_EmailTest extends CiviUnitTestCase { $userID = $this->createLoggedInUser(); $mut = new CiviMailUtils($this); Civi::settings()->set('allow_mail_from_logged_in_contact', TRUE); - $this->callAPISuccess('Email', 'create', [ + $emailID = $this->callAPISuccess('Email', 'create', [ 'contact_id' => $userID, 'email' => 'benny_jetts@example.com', 'signature_html' => 'Benny, Benny', 'is_primary' => 1, - ]); + ])['id']; $contribution1 = $this->contributionCreate(['contact_id' => $contact2, 'invoice_number' => 'soy']); $contribution2 = $this->contributionCreate(['total_amount' => 999, 'contact_id' => $contact1, 'invoice_number' => 'saucy']); $contribution3 = $this->contributionCreate(['total_amount' => 999, 'contact_id' => $contact1, 'invoice_number' => 'ranch']); @@ -58,6 +58,7 @@ class CRM_Contribute_Form_Task_EmailTest extends CiviUnitTestCase { 'subject' => '{contact.display_name} {contribution.total_amount}', 'text_message' => '{contribution.financial_type_id:label} {contribution.invoice_number}', 'html_message' => '{domain.name}', + 'from_email_address' => $emailID, ], [], [ 'radio_ts' => 'ts_sel', 'task' => CRM_Core_Task::TASK_EMAIL, -- 2.25.1