Skip to content

Commit

Permalink
Fix values passed to tokenValues hook
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwire committed Apr 5, 2020
1 parent cb94806 commit 590111e
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 18 deletions.
1 change: 1 addition & 0 deletions CRM/Contact/Form/Task/Label.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ public function postProcess($params = NULL) {
$details = $query->apiQuery($params, $returnProperties, NULL, NULL, 0, $numberofContacts, TRUE, FALSE, TRUE, CRM_Contact_BAO_Query::MODE_CONTACTS, NULL, $primaryLocationOnly);
$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,
Expand Down
1 change: 1 addition & 0 deletions CRM/Contact/Form/Task/LabelCommon.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
12 changes: 6 additions & 6 deletions CRM/Mailing/BAO/Mailing.php
Original file line number Diff line number Diff line change
Expand Up @@ -1080,15 +1080,18 @@ 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);
// $contact is an array of [ contactID => contactDetails ]

//CRM-4524
$contact = reset($contact);
// also call the hook to get contact details
CRM_Utils_Hook::tokenValues($contact, [$contactId], $job_id);

// Don't send if contact doesn't exist
$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]
Expand All @@ -1098,9 +1101,6 @@ public function compose(
$res = NULL;
return $res;
}

// also call the hook to get contact details
CRM_Utils_Hook::tokenValues($contact, $contactId, $job_id);
}

$pTemplates = $this->getPreparedTemplates();
Expand Down
2 changes: 1 addition & 1 deletion CRM/Mailing/Page/Preview.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down
2 changes: 1 addition & 1 deletion CRM/Utils/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,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
Expand Down
8 changes: 3 additions & 5 deletions CRM/Utils/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
7 changes: 2 additions & 5 deletions Civi/Token/TokenCompatSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,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']
Expand Down

0 comments on commit 590111e

Please sign in to comment.