Skip to content

Commit

Permalink
Merge pull request #16929 from eileenmcnaughton/email2
Browse files Browse the repository at this point in the history
[REF] extract code to getEmails
  • Loading branch information
colemanw authored Mar 31, 2020
2 parents ff3b82e + 3ab7a12 commit 8742ba9
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions CRM/Contact/Form/Task/EmailCommon.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ public static function buildQuickForm(&$form) {
$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;
Expand All @@ -115,13 +118,10 @@ public static function buildQuickForm(&$form) {
$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':
Expand Down Expand Up @@ -594,4 +594,21 @@ public static function bounceIfSimpleMailLimitExceeded($count) {
}
}

/**
* 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;
}

}

0 comments on commit 8742ba9

Please sign in to comment.