From: Eileen McNaughton Date: Sun, 8 Aug 2021 23:43:04 +0000 (+1200) Subject: [Ref] extract function to getEmailDefaults X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=d7b498bcf90af9e96fce254690279cfffef81dac;p=civicrm-core.git [Ref] extract function to getEmailDefaults Part of terminally deprecating the EmailCommon class --- diff --git a/CRM/Contact/Form/Task/EmailCommon.php b/CRM/Contact/Form/Task/EmailCommon.php index 8244a9440b..07b0e8247d 100644 --- a/CRM/Contact/Form/Task/EmailCommon.php +++ b/CRM/Contact/Form/Task/EmailCommon.php @@ -28,7 +28,7 @@ class CRM_Contact_Form_Task_EmailCommon { * @param CRM_Core_Form $form * @param bool $bounce determine if we want to throw a status bounce. * - * @throws \CiviCRM_API3_Exception + * @throws \API_Exception */ public static function preProcessFromAddress(&$form, $bounce = TRUE) { $form->_emails = []; @@ -49,20 +49,13 @@ class CRM_Contact_Form_Task_EmailCommon { $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)); } - if (is_numeric(key($form->_fromEmails))) { - // Add signature - $defaultEmail = civicrm_api3('email', 'getsingle', ['id' => key($form->_fromEmails)]); - $defaults = []; - if (!empty($defaultEmail['signature_html'])) { - $defaults['html_message'] = '

--' . $defaultEmail['signature_html']; - } - if (!empty($defaultEmail['signature_text'])) { - $defaults['text_message'] = "\n\n--\n" . $defaultEmail['signature_text']; - } - } $form->setDefaults($defaults); } diff --git a/CRM/Contact/Form/Task/EmailTrait.php b/CRM/Contact/Form/Task/EmailTrait.php index 31ec4f8031..d87cea587c 100644 --- a/CRM/Contact/Form/Task/EmailTrait.php +++ b/CRM/Contact/Form/Task/EmailTrait.php @@ -118,10 +118,11 @@ trait CRM_Contact_Form_Task_EmailTrait { * Call trait preProcess function. * * This function exists as a transitional arrangement so classes overriding - * preProcess can still call it. Ideally it will be melded into preProcess later. + * preProcess can still call it. Ideally it will be melded into preProcess + * later. * - * @throws \CiviCRM_API3_Exception * @throws \CRM_Core_Exception + * @throws \API_Exception */ protected function traitPreProcess() { CRM_Contact_Form_Task_EmailCommon::preProcessFromAddress($this); diff --git a/CRM/Core/BAO/Email.php b/CRM/Core/BAO/Email.php index 1e947294a5..5341997ecb 100644 --- a/CRM/Core/BAO/Email.php +++ b/CRM/Core/BAO/Email.php @@ -15,6 +15,8 @@ * @copyright CiviCRM LLC https://civicrm.org/licensing */ +use Civi\Api4\Email; + /** * This class contains functions for email handling. */ @@ -383,4 +385,25 @@ AND reset_date IS NULL } } + /** + * Get default text for a message with the signature from the email sender populated. + * + * @param int $emailID + * + * @return array + * + * @throws \API_Exception + * @throws \Civi\API\Exception\UnauthorizedException + */ + public static function getEmailSignatureDefaults(int $emailID): array { + // Add signature + $defaultEmail = Email::get(FALSE) + ->addSelect('signature_html', 'signature_text') + ->addWhere('id', '=', $emailID)->execute()->first(); + return [ + 'html_message' => empty($defaultEmail['signature_html']) ? '' : '

--' . $defaultEmail['signature_html'], + 'text_message' => empty($defaultEmail['signature_text']) ? '' : "\n\n--\n" . $defaultEmail['signature_text'], + ]; + } + }