From 3ab7a12b043f0c066e3765fbce995cf9d729bf45 Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 31 Mar 2020 17:51:01 +1300 Subject: [PATCH] [REF] extract code to getEmails --- CRM/Contact/Form/Task/EmailCommon.php | 29 +++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/CRM/Contact/Form/Task/EmailCommon.php b/CRM/Contact/Form/Task/EmailCommon.php index 750c8ea1b7..2063a4ffee 100644 --- a/CRM/Contact/Form/Task/EmailCommon.php +++ b/CRM/Contact/Form/Task/EmailCommon.php @@ -115,6 +115,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; @@ -124,13 +127,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': @@ -603,4 +603,21 @@ 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 { + $allEmails = explode(',', $element->getValue()); + $return = []; + foreach ($allEmails as $value) { + $values = explode('::', $value); + $return[] = ['contact_id' => $values[0], 'email' => $values[1]]; + } + return $return; + } + } -- 2.25.1