From 33ced9a45265a3ec6e21af08e8478842093dd485 Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 26 May 2020 16:37:27 +1200 Subject: [PATCH] Switch to an api call to get the contact details. It's much clearer that it's just a basic get. Using v4 means I have to param wrangle so I stuck with v3 for now (i.e if I switch to Email.get which I think I need to for v4 since Primary.email is not a v4 search param I wind up with prefixes on the keys --- CRM/Contact/Form/Task/EmailTrait.php | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/CRM/Contact/Form/Task/EmailTrait.php b/CRM/Contact/Form/Task/EmailTrait.php index 97b4347027..0cd65b4e09 100644 --- a/CRM/Contact/Form/Task/EmailTrait.php +++ b/CRM/Contact/Form/Task/EmailTrait.php @@ -206,26 +206,15 @@ trait CRM_Contact_Form_Task_EmailTrait { // check if we need to setdefaults and check for valid contact emails / communication preferences if (is_array($this->_allContactIds) && $setDefaults) { - $returnProperties = [ - 'sort_name' => 1, - 'email' => 1, - 'do_not_email' => 1, - 'is_deceased' => 1, - 'on_hold' => 1, - 'display_name' => 1, - 'preferred_mail_format' => 1, - ]; - // get the details for all selected contacts ( to, cc and bcc contacts ) - list($this->_allContactDetails) = CRM_Utils_Token::getTokenDetails($this->_allContactIds, - $returnProperties, - FALSE, - FALSE - ); + $allContactDetails = civicrm_api3('Contact', 'get', [ + 'id' => ['IN' => $this->_allContactIds], + 'return' => ['sort_name', 'email', 'do_not_email', 'is_deceased', 'on_hold', 'display_name', 'preferred_mail_format'], + 'options' => ['limit' => 0], + ])['values']; // perform all validations on unique contact Ids - foreach (array_unique($this->_allContactIds) as $key => $contactId) { - $value = $this->_allContactDetails[$contactId]; + foreach ($allContactDetails as $contactId => $value) { if ($value['do_not_email'] || empty($value['email']) || !empty($value['is_deceased']) || $value['on_hold']) { $this->setSuppressedEmail($contactId, $value); } @@ -234,7 +223,7 @@ trait CRM_Contact_Form_Task_EmailTrait { // build array's which are used to setdefaults if (in_array($contactId, $this->_toContactIds)) { - $this->_toContactDetails[$contactId] = $this->_contactDetails[$contactId] = $this->_allContactDetails[$contactId]; + $this->_toContactDetails[$contactId] = $this->_contactDetails[$contactId] = $value; // If a particular address has been specified as the default, use that instead of contact's primary email if (!empty($this->_toEmail) && $this->_toEmail['contact_id'] == $contactId) { $email = $this->_toEmail['email']; -- 2.25.1