Merge pull request #18143 from mattwire/membertabbuttons
[civicrm-core.git] / CRM / Contact / Form / Task / EmailCommon.php
index 10d38cb4637e53f5d7754627e59fd6904d183520..1244b44f3a0db7d23f2d55c09b09349e48e98bbf 100644 (file)
@@ -30,15 +30,6 @@ class CRM_Contact_Form_Task_EmailCommon {
 
   public $_toContactEmails = [];
 
-  /**
-   * @return array $domainEmails;
-   * @deprecated Generate an array of Domain email addresses.
-   */
-  public static function domainEmails() {
-    CRM_Core_Error::deprecatedFunctionWarning('CRM_Core_BAO_Email::domainEmails()');
-    return CRM_Core_BAO_Email::domainEmails();
-  }
-
   /**
    * Pre Process Form Addresses to be used in Quickform
    *
@@ -48,13 +39,9 @@ class CRM_Contact_Form_Task_EmailCommon {
    * @throws \CiviCRM_API3_Exception
    */
   public static function preProcessFromAddress(&$form, $bounce = TRUE) {
-    $form->_single = FALSE;
-    $className = CRM_Utils_System::getClassName($form);
-    if (property_exists($form, '_context') &&
-      $form->_context != 'search' &&
-      $className == 'CRM_Contact_Form_Task_Email'
-    ) {
-      $form->_single = TRUE;
+    if (!isset($form->_single)) {
+      // @todo ensure this is already set.
+      $form->_single = FALSE;
     }
 
     $form->_emails = [];
@@ -100,6 +87,7 @@ class CRM_Contact_Form_Task_EmailCommon {
    * @throws \CRM_Core_Exception
    */
   public static function buildQuickForm(&$form) {
+    CRM_Core_Error::deprecatedFunctionWarning('This code is no longer used in core and will be removed');
     $toArray = $ccArray = $bccArray = [];
     $suppressedEmails = 0;
     //here we are getting logged in user id as array but we need target contact id. CRM-5988
@@ -119,6 +107,9 @@ class CRM_Contact_Form_Task_EmailCommon {
     $cc = $form->add('text', 'cc_id', ts('CC'), $emailAttributes);
     $bcc = $form->add('text', 'bcc_id', ts('BCC'), $emailAttributes);
 
+    if ($to->getValue()) {
+      $form->_toContactIds = $form->_contactIds = [];
+    }
     $setDefaults = TRUE;
     if (property_exists($form, '_context') && $form->_context == 'standalone') {
       $setDefaults = FALSE;
@@ -128,13 +119,10 @@ class CRM_Contact_Form_Task_EmailCommon {
     $form->_allContactIds = $form->_toContactIds = $form->_contactIds;
     foreach ($elements as $element) {
       if ($$element->getValue()) {
-        $allEmails = explode(',', $$element->getValue());
-        if ($element == 'to') {
-          $form->_toContactIds = $form->_contactIds = [];
-        }
 
-        foreach ($allEmails as $value) {
-          list($contactId, $email) = explode('::', $value);
+        foreach (self::getEmails($$element) as $value) {
+          $contactId = $value['contact_id'];
+          $email = $value['email'];
           if ($contactId) {
             switch ($element) {
               case 'to':
@@ -368,6 +356,8 @@ class CRM_Contact_Form_Task_EmailCommon {
    * @throws \Civi\API\Exception\UnauthorizedException
    */
   public static function postProcess(&$form) {
+    CRM_Core_Error::deprecatedFunctionWarning('This code is no longer used in core and will be removed');
+
     self::bounceIfSimpleMailLimitExceeded(count($form->_contactIds));
 
     // check and ensure that
@@ -388,6 +378,8 @@ class CRM_Contact_Form_Task_EmailCommon {
    * @throws \Civi\API\Exception\UnauthorizedException
    */
   public static function submit(&$form, $formValues) {
+    CRM_Core_Error::deprecatedFunctionWarning('This code is no longer used in core and will be removed');
+
     self::saveMessageTemplate($formValues);
 
     $from = $formValues['from_email_address'] ?? NULL;
@@ -571,6 +563,8 @@ class CRM_Contact_Form_Task_EmailCommon {
    * @throws \Civi\API\Exception\UnauthorizedException
    */
   protected static function saveMessageTemplate($formValues) {
+    CRM_Core_Error::deprecatedFunctionWarning('This code is no longer used in core and will be removed');
+
     if (!empty($formValues['saveTemplate']) || !empty($formValues['updateTemplate'])) {
       $messageTemplate = [
         'msg_text' => $formValues['text_message'],
@@ -599,6 +593,8 @@ class CRM_Contact_Form_Task_EmailCommon {
    *  The number of emails the user is attempting to send
    */
   public static function bounceIfSimpleMailLimitExceeded($count) {
+    CRM_Core_Error::deprecatedFunctionWarning('This code is no longer used in core and will be removed');
+
     $limit = Civi::settings()->get('simple_mail_limit');
     if ($count > $limit) {
       CRM_Core_Error::statusBounce(ts('Please do not use this task to send a lot of emails (greater than %1). Many countries have legal requirements when sending bulk emails and the CiviMail framework has opt out functionality and domain tokens to help meet these.',
@@ -607,4 +603,23 @@ class CRM_Contact_Form_Task_EmailCommon {
     }
   }
 
+  /**
+   * Get the emails from the added element.
+   *
+   * @param HTML_QuickForm_Element $element
+   *
+   * @return array
+   */
+  protected static function getEmails($element): array {
+    CRM_Core_Error::deprecatedFunctionWarning('This code is no longer used in core and will be removed');
+
+    $allEmails = explode(',', $element->getValue());
+    $return = [];
+    foreach ($allEmails as $value) {
+      $values = explode('::', $value);
+      $return[] = ['contact_id' => $values[0], 'email' => $values[1]];
+    }
+    return $return;
+  }
+
 }