Skip to content

Commit

Permalink
Switch cc field on emailTrait to use entity reference
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Apr 21, 2020
1 parent 53ad44b commit 21b0ad3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 39 deletions.
48 changes: 10 additions & 38 deletions CRM/Contact/Form/Task/EmailTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function buildQuickForm() {
$this->assign('suppressForm', FALSE);
$this->assign('emailTask', TRUE);

$toArray = $ccArray = [];
$toArray = [];
$suppressedEmails = 0;
//here we are getting logged in user id as array but we need target contact id. CRM-5988
$cid = $this->get('cid');
Expand All @@ -155,7 +155,11 @@ public function buildQuickForm() {
'class' => 'huge',
];
$to = $this->add('text', 'to', ts('To'), $emailAttributes, TRUE);
$cc = $this->add('text', 'cc_id', ts('CC'), $emailAttributes);

$this->addEntityRef('cc_id', ts('CC'), [
'entity' => 'Email',
'multiple' => TRUE,
]);

$this->addEntityRef('bcc_id', ts('BCC'), [
'entity' => 'Email',
Expand All @@ -170,7 +174,7 @@ public function buildQuickForm() {
$setDefaults = FALSE;
}

$elements = ['to', 'cc'];
$elements = ['to'];
$this->_allContactIds = $this->_toContactIds = $this->_contactIds;
foreach ($elements as $element) {
if ($$element->getValue()) {
Expand All @@ -185,9 +189,6 @@ public function buildQuickForm() {
$this->_toContactEmails[] = $email;
break;

case 'cc':
$this->_ccContactIds[] = $contactId;
break;
}

$this->_allContactIds[] = $contactId;
Expand Down Expand Up @@ -251,12 +252,6 @@ public function buildQuickForm() {
'id' => "$contactId::{$email}",
];
}
elseif (in_array($contactId, $this->_ccContactIds)) {
$ccArray[] = [
'text' => '"' . $value['sort_name'] . '" <' . $email . '>',
'id' => "$contactId::{$email}",
];
}
}
}

Expand All @@ -266,7 +261,6 @@ public function buildQuickForm() {
}

$this->assign('toContact', json_encode($toArray));
$this->assign('ccContact', json_encode($ccArray));

$this->assign('suppressedEmails', $suppressedEmails);

Expand Down Expand Up @@ -412,32 +406,10 @@ public function submit($formValues) {
$from = CRM_Utils_Mail::formatFromAddress($from);
$subject = $formValues['subject'];

// CRM-13378: Append CC and BCC information at the end of Activity Details and format cc and bcc fields
$elements = ['cc_id'];
$additionalDetails = NULL;
$ccValues = [];
foreach ($elements as $element) {
if (!empty($formValues[$element])) {
$allEmails = explode(',', $formValues[$element]);
foreach ($allEmails as $value) {
list($contactId, $email) = explode('::', $value);
$contactURL = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$contactId}", TRUE);
switch ($element) {
case 'cc_id':
$ccValues['email'][] = '"' . $this->_contactDetails[$contactId]['sort_name'] . '" <' . $email . '>';
$ccValues['details'][] = "<a href='{$contactURL}'>" . $this->_contactDetails[$contactId]['display_name'] . "</a>";
break;

}
}
}
}
$cc = '';
$ccArray = explode(',', $formValues['cc_id'] ?? '');
$cc = $this->getEmailString($ccArray);
$additionalDetails = empty($ccArray) ? '' : "\ncc : " . $this->getEmailUrlString($ccArray);

if (!empty($ccValues)) {
$cc = implode(',', $ccValues['email']);
$additionalDetails .= "\ncc : " . implode(", ", $ccValues['details']);
}
$bccArray = explode(',', $formValues['bcc_id'] ?? '');
$bcc = $this->getEmailString($bccArray);
$additionalDetails .= empty($bccArray) ? '' : "\nbcc : " . $this->getEmailUrlString($bccArray);
Expand Down
1 change: 0 additions & 1 deletion templates/CRM/Contact/Form/Task/Email.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ CRM.$(function($) {
ccContact = {if $ccContact}{$ccContact}{else}''{/if};
{literal}
emailSelect('#to', toContact);
emailSelect('#cc_id', ccContact);
});
Expand Down

0 comments on commit 21b0ad3

Please sign in to comment.