[REF] Simplify subject code. Note sendEmail
authoreileen <emcnaughton@wikimedia.org>
Tue, 26 May 2020 02:58:37 +0000 (14:58 +1200)
committereileen <emcnaughton@wikimedia.org>
Sun, 31 May 2020 22:23:46 +0000 (10:23 +1200)
is only called from this, some tests, and a deprecated function (unused in core) so we can change
it to not pass by reference safely

CRM/Contact/Form/Task/EmailTrait.php

index 97b4347027224aab94e0c12cee6c716f122fdc23..027f767fcc21decf5132d32e65aa0406e2f45954 100644 (file)
@@ -397,7 +397,6 @@ trait CRM_Contact_Form_Task_EmailTrait {
     // 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" <toemailaddress>
     $from = CRM_Utils_Mail::formatFromAddress($from);
-    $subject = $formValues['subject'];
 
     $ccArray = $formValues['cc_id'] ? explode(',', $formValues['cc_id']) : [];
     $cc = $this->getEmailString($ccArray);
@@ -407,12 +406,6 @@ trait CRM_Contact_Form_Task_EmailTrait {
     $bcc = $this->getEmailString($bccArray);
     $additionalDetails .= empty($bccArray) ? '' : "\nbcc : " . $this->getEmailUrlString($bccArray);
 
-    // CRM-5916: prepend case id hash to CiviCase-originating emails’ subjects
-    if (isset($this->_caseId) && is_numeric($this->_caseId)) {
-      $hash = substr(sha1(CIVICRM_SITE_KEY . $this->_caseId), 0, 7);
-      $subject = "[case #$hash] $subject";
-    }
-
     // format contact details array to handle multiple emails from same contact
     $formattedContactDetails = [];
     foreach ($this->_contactIds as $key => $contactId) {
@@ -438,7 +431,7 @@ trait CRM_Contact_Form_Task_EmailTrait {
     // send the mail
     list($sent, $activityId) = CRM_Activity_BAO_Activity::sendEmail(
       $formattedContactDetails,
-      $subject,
+      $this->getSubject($formValues['subject']),
       $formValues['text_message'],
       $formValues['html_message'],
       NULL,
@@ -643,4 +636,22 @@ trait CRM_Contact_Form_Task_EmailTrait {
     return $attachments;
   }
 
+  /**
+   * Get the subject for the message.
+   *
+   * The case handling should possibly be on the case form.....
+   *
+   * @param string $subject
+   *
+   * @return string
+   */
+  protected function getSubject(string $subject):string {
+    // CRM-5916: prepend case id hash to CiviCase-originating emails’ subjects
+    if (isset($this->_caseId) && is_numeric($this->_caseId)) {
+      $hash = substr(sha1(CIVICRM_SITE_KEY . $this->_caseId), 0, 7);
+      $subject = "[case #$hash] $subject";
+    }
+    return $subject;
+  }
+
 }