From 299f2c8f2eb545a006b1cf7f681c0b49d88404e5 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 25 Aug 2021 19:35:32 +1200 Subject: [PATCH] [Ref] Copy emailcommon function back to email trait This is part of ending the email common trait. It is currently 'shared' with a couple of other places - but most of the functionality is not that shared & could be easily cleaned up when separated out. I want to create a trait for PdfTrait like the email trait so getting the email trait better separated for that --- CRM/Contact/Form/Task/EmailTrait.php | 49 ++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/CRM/Contact/Form/Task/EmailTrait.php b/CRM/Contact/Form/Task/EmailTrait.php index 991b12cfca..2e78e168a4 100644 --- a/CRM/Contact/Form/Task/EmailTrait.php +++ b/CRM/Contact/Form/Task/EmailTrait.php @@ -55,19 +55,6 @@ trait CRM_Contact_Form_Task_EmailTrait { */ public $_toContactIds = []; - /** - * Store only "cc" contact ids. - * @var array - */ - public $_ccContactIds = []; - - /** - * Store only "bcc" contact ids. - * - * @var array - */ - public $_bccContactIds = []; - /** * Is the form being loaded from a search action. * @@ -125,7 +112,7 @@ trait CRM_Contact_Form_Task_EmailTrait { * @throws \API_Exception */ protected function traitPreProcess() { - CRM_Contact_Form_Task_EmailCommon::preProcessFromAddress($this); + $this->preProcessFromAddress(); if ($this->isSearchContext()) { // Currently only the contact email form is callable outside search context. parent::preProcess(); @@ -137,6 +124,40 @@ trait CRM_Contact_Form_Task_EmailTrait { } } + /** + * Pre Process Form Addresses to be used in Quickform + * + * @throws \API_Exception + * @throws \CRM_Core_Exception + */ + protected function preProcessFromAddress(): void { + $form = $this; + $form->_emails = []; + + // @TODO remove these line and to it somewhere more appropriate. Currently some classes (e.g Case + // are having to re-write contactIds afterwards due to this inappropriate variable setting + // If we don't have any contact IDs, use the logged in contact ID + $form->_contactIds = $form->_contactIds ?: [CRM_Core_Session::getLoggedInContactID()]; + + $fromEmailValues = CRM_Core_BAO_Email::getFromEmail(); + + if (empty($fromEmailValues)) { + CRM_Core_Error::statusBounce(ts('Your user record does not have a valid email address and no from addresses have been configured.')); + } + + $form->_emails = $fromEmailValues; + $defaults = []; + $form->_fromEmails = $fromEmailValues; + if (is_numeric(key($form->_fromEmails))) { + $emailID = (int) key($form->_fromEmails); + $defaults = CRM_Core_BAO_Email::getEmailSignatureDefaults($emailID); + } + if (!Civi::settings()->get('allow_mail_from_logged_in_contact')) { + $defaults['from_email_address'] = current(CRM_Core_BAO_Domain::getNameAndEmail(FALSE, TRUE)); + } + $form->setDefaults($defaults); + } + /** * Build the form object. * -- 2.25.1