Skip to content

Commit

Permalink
Change email to entity reference
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Apr 6, 2020
1 parent 51dad0b commit 1237865
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
13 changes: 5 additions & 8 deletions CRM/Contact/Form/Task/EmailTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,12 @@ public function buildQuickForm() {
];
$to = $this->add('text', 'to', ts('To'), $emailAttributes, TRUE);
$cc = $this->add('text', 'cc_id', ts('CC'), $emailAttributes);
$bcc = $this->add('text', 'bcc_id', ts('BCC'), $emailAttributes);

$this->addEntityRef('bcc_id', ts('BCC'), [
'entity' => 'Email',
'multiple' => TRUE,
'api'=> ['params' => ['on_hold' => 0, 'contact_id.do_not_email' => 0]]
]);
$setDefaults = TRUE;
if (property_exists($this, '_context') && $this->_context === 'standalone') {
$setDefaults = FALSE;
Expand All @@ -183,13 +187,6 @@ public function buildQuickForm() {
}
}

if ($bcc->getValue()) {
foreach ($this->getEmails($bcc) as $value) {
if (!empty($value['contact_id'])) {
$this->_bccContactIds[] = $value['contact_id'];
}
}
}
$this->_allContactIds = array_unique(array_merge($this->_contactIds, $this->_ccContactIds, $this->_bccContactIds));
$setDefaults = empty($this->_allContactIds) ? $setDefaults: TRUE;

Expand Down
20 changes: 20 additions & 0 deletions CRM/Core/BAO/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,24 @@ public static function del($id) {
return CRM_Contact_BAO_Contact::deleteObjectWithPrimary('Email', $id);
}

/**
* Get filters for entity reference fields.
*
* @return array
*/
public static function getEntityRefFilters() {
$contactFields = CRM_Contact_BAO_Contact::getEntityRefFilters();
foreach ($contactFields as $index => &$contactField) {
if (!empty($contactField['entity'])) {
// For now email_getlist can't parse state, country etc.
unset($contactFields[$index]);
}
elseif ($contactField['key'] !== 'contact_id') {
$contactField['entity'] = 'Contact';
$contactField['key'] = 'contact_id.' . $contactField['key'];
}
}
return $contactFields;
}

}
2 changes: 1 addition & 1 deletion templates/CRM/Contact/Form/Task/Email.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ CRM.$(function($) {
{literal}
emailSelect('#to', toContact);
emailSelect('#cc_id', ccContact);
emailSelect('#bcc_id', bccContact);
//emailSelect('#bcc_id', bccContact);
});
Expand Down

0 comments on commit 1237865

Please sign in to comment.