From: eileen Date: Tue, 9 May 2017 08:52:04 +0000 (+1200) Subject: Minor readability adjustments X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=ed999bcd8aef533e126959c0625480c7c60cfee7;p=civicrm-core.git Minor readability adjustments --- diff --git a/CRM/Contact/Form/Task/EmailCommon.php b/CRM/Contact/Form/Task/EmailCommon.php index 7f202d89d6..b9217068cd 100644 --- a/CRM/Contact/Form/Task/EmailCommon.php +++ b/CRM/Contact/Form/Task/EmailCommon.php @@ -74,18 +74,14 @@ class CRM_Contact_Form_Task_EmailCommon { $form->_emails = $emails = array(); - $session = CRM_Core_Session::singleton(); - $contactID = $session->get('userID'); + $contactID = CRM_Core_Session::singleton()->getLoggedInContactID(); + $fromDisplayName = CRM_Core_Session::singleton()->getLoggedInContactDisplayName(); $form->_contactIds = array($contactID); $contactEmails = CRM_Core_BAO_Email::allEmails($contactID); $form->_onHold = array(); - $fromDisplayName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', - $contactID, 'display_name' - ); - foreach ($contactEmails as $emailId => $item) { $email = $item['email']; if (!$email && (count($emails) < 1)) { @@ -418,8 +414,9 @@ class CRM_Contact_Form_Task_EmailCommon { // check and ensure that $formValues = $form->controller->exportValues($form->getName()); - $fromEmail = $formValues['fromEmailAddress']; - $from = CRM_Utils_Array::value($fromEmail, $form->_emails); + self::saveMessageTemplate($formValues); + + $from = CRM_Utils_Array::value($formValues['fromEmailAddress'], $form->_emails); $subject = $formValues['subject']; // CRM-13378: Append CC and BCC information at the end of Activity Details and format cc and bcc fields @@ -463,27 +460,6 @@ class CRM_Contact_Form_Task_EmailCommon { $subject = "[case #$hash] $subject"; } - // process message template - if (!empty($formValues['saveTemplate']) || !empty($formValues['updateTemplate'])) { - $messageTemplate = array( - 'msg_text' => $formValues['text_message'], - 'msg_html' => $formValues['html_message'], - 'msg_subject' => $formValues['subject'], - 'is_active' => TRUE, - ); - - if (!empty($formValues['saveTemplate'])) { - $messageTemplate['msg_title'] = $formValues['saveTemplateName']; - CRM_Core_BAO_MessageTemplate::add($messageTemplate); - } - - if (!empty($formValues['template']) && !empty($formValues['updateTemplate'])) { - $messageTemplate['id'] = $formValues['template']; - unset($messageTemplate['msg_title']); - CRM_Core_BAO_MessageTemplate::add($messageTemplate); - } - } - $attachments = array(); CRM_Core_BAO_File::formatAttachment($formValues, $attachments, @@ -607,4 +583,31 @@ class CRM_Contact_Form_Task_EmailCommon { } } + /** + * Save the template if update selected. + * + * @param array $formValues + */ + protected static function saveMessageTemplate($formValues) { + if (!empty($formValues['saveTemplate']) || !empty($formValues['updateTemplate'])) { + $messageTemplate = array( + 'msg_text' => $formValues['text_message'], + 'msg_html' => $formValues['html_message'], + 'msg_subject' => $formValues['subject'], + 'is_active' => TRUE, + ); + + if (!empty($formValues['saveTemplate'])) { + $messageTemplate['msg_title'] = $formValues['saveTemplateName']; + CRM_Core_BAO_MessageTemplate::add($messageTemplate); + } + + if (!empty($formValues['template']) && !empty($formValues['updateTemplate'])) { + $messageTemplate['id'] = $formValues['template']; + unset($messageTemplate['msg_title']); + CRM_Core_BAO_MessageTemplate::add($messageTemplate); + } + } + } + } diff --git a/tests/phpunit/CRM/Contact/Form/Task/EmailCommonTest.php b/tests/phpunit/CRM/Contact/Form/Task/EmailCommonTest.php index 9717d62dd5..10bd5d2ee0 100644 --- a/tests/phpunit/CRM/Contact/Form/Task/EmailCommonTest.php +++ b/tests/phpunit/CRM/Contact/Form/Task/EmailCommonTest.php @@ -45,7 +45,7 @@ class CRM_Contact_Form_Task_EmailCommonTest extends CiviUnitTestCase { /** * Test generating domain emails */ - public function testDomainEmailGeneation() { + public function testDomainEmailGeneration() { $emails = CRM_Contact_Form_Task_EmailCommon::domainEmails(); $this->assertNotEmpty($emails); $optionValue = $this->callAPISuccess('OptionValue', 'Get', array(