diff --git a/CRM/Contact/Form/Task/Label.php b/CRM/Contact/Form/Task/Label.php index c297cd3a07dd..ba2761e68d56 100644 --- a/CRM/Contact/Form/Task/Label.php +++ b/CRM/Contact/Form/Task/Label.php @@ -204,6 +204,7 @@ public function postProcess() { $messageToken = CRM_Utils_Token::getTokens($mailingFormat); + // $details[0] is an array of [ contactID => contactDetails ] // also get all token values CRM_Utils_Hook::tokenValues($details[0], $this->_contactIds, diff --git a/CRM/Contact/Form/Task/LabelCommon.php b/CRM/Contact/Form/Task/LabelCommon.php index b35673517666..60d344e4bc2c 100644 --- a/CRM/Contact/Form/Task/LabelCommon.php +++ b/CRM/Contact/Form/Task/LabelCommon.php @@ -140,6 +140,7 @@ public static function getRows($contactIDs, $locationTypeID, $respectDoNotMail, $details = $query->apiQuery($params, $returnProperties, NULL, NULL, 0, $numberofContacts); $messageToken = CRM_Utils_Token::getTokens($mailingFormat); + // $details[0] is an array of [ contactID => contactDetails ] $details = $details[0]; $tokenFields = CRM_Contact_Form_Task_LabelCommon::getTokenData($details); diff --git a/CRM/Mailing/BAO/Mailing.php b/CRM/Mailing/BAO/Mailing.php index 59c588221cc5..0f5f78ecfa76 100644 --- a/CRM/Mailing/BAO/Mailing.php +++ b/CRM/Mailing/BAO/Mailing.php @@ -1080,27 +1080,15 @@ public function compose( elseif ($contactId === 0) { //anonymous user $contact = []; - CRM_Utils_Hook::tokenValues($contact, $contactId, $job_id); + CRM_Utils_Hook::tokenValues($contact, [$contactId], $job_id); } else { $params = [['contact_id', '=', $contactId, 0, 0]]; list($contact) = CRM_Contact_BAO_Query::apiQuery($params); - - //CRM-4524 - $contact = reset($contact); - - if (!$contact || is_a($contact, 'CRM_Core_Error')) { - CRM_Core_Error::debug_log_message(ts('CiviMail will not send email to a non-existent contact: %1', - [1 => $contactId] - )); - // setting this because function is called by reference - //@todo test not calling function by reference - $res = NULL; - return $res; - } + // $contact is an array of [ contactID => contactDetails ] // also call the hook to get contact details - CRM_Utils_Hook::tokenValues($contact, $contactId, $job_id); + CRM_Utils_Hook::tokenValues($contact, [$contactId], $job_id); } $pTemplates = $this->getPreparedTemplates(); diff --git a/CRM/Mailing/Page/Preview.php b/CRM/Mailing/Page/Preview.php index 85daed2ee3a0..6221e1063c34 100644 --- a/CRM/Mailing/Page/Preview.php +++ b/CRM/Mailing/Page/Preview.php @@ -66,7 +66,7 @@ public function run() { $mailing->getFlattenedTokens(), get_class($this) ); - + // $details[0] is an array of [ contactID => contactDetails ] $mime = &$mailing->compose(NULL, NULL, NULL, $session->get('userID'), $fromEmail, $fromEmail, TRUE, $details[0][$session->get('userID')], $attachments ); diff --git a/CRM/Utils/Hook.php b/CRM/Utils/Hook.php index 31663cacf55f..58652706fba7 100644 --- a/CRM/Utils/Hook.php +++ b/CRM/Utils/Hook.php @@ -854,7 +854,7 @@ public static function alterAdminPanel(&$panels) { * tokens returned by the 'tokens' hook * * @param array $details - * The array to store the token values indexed by contactIDs (unless it a single). + * The array to store the token values indexed by contactIDs. * @param array $contactIDs * An array of contactIDs. * @param int $jobID diff --git a/CRM/Utils/Token.php b/CRM/Utils/Token.php index 156f87a279d7..e1feafa88505 100644 --- a/CRM/Utils/Token.php +++ b/CRM/Utils/Token.php @@ -1228,7 +1228,6 @@ public static function getTokenDetails( } $details = CRM_Contact_BAO_Query::apiQuery($params, $returnProperties, NULL, NULL, 0, count($contactIDs), TRUE, FALSE, TRUE, CRM_Contact_BAO_Query::MODE_CONTACTS, NULL, TRUE); - $contactDetails = &$details[0]; foreach ($contactIDs as $contactID) { @@ -1263,8 +1262,9 @@ public static function getTokenDetails( } } + // $contactDetails = &$details[0] = is an array of [ contactID => contactDetails ] // also call a hook and get token details - CRM_Utils_Hook::tokenValues($details[0], + CRM_Utils_Hook::tokenValues($contactDetails, $contactIDs, $jobID, $tokens, @@ -1291,9 +1291,7 @@ public static function getTokenDetails( * @return array * contactDetails with hooks swapped out */ - public static function getAnonymousTokenDetails($contactIDs = [ - 0, - ], + public static function getAnonymousTokenDetails($contactIDs = [0], $returnProperties = NULL, $skipOnHold = TRUE, $skipDeceased = TRUE, diff --git a/Civi/Token/TokenCompatSubscriber.php b/Civi/Token/TokenCompatSubscriber.php index 672080d29ba4..a573337ad96c 100644 --- a/Civi/Token/TokenCompatSubscriber.php +++ b/Civi/Token/TokenCompatSubscriber.php @@ -88,12 +88,9 @@ public function onEvaluate(TokenValueEvent $e) { $contact = array_merge($contact, $row->context['tmpTokenParams']); } - $contactArray = !is_array($contactId) ? [$contactId => $contact] : $contact; - - // Note: This is a small contract change from the past; data should be missing - // less randomly. + $contactArray = [$contactId => $contact]; \CRM_Utils_Hook::tokenValues($contactArray, - (array) $contactId, + [$contactId], empty($row->context['mailingJobId']) ? NULL : $row->context['mailingJobId'], $messageTokens, $row->context['controller']