Warning that $greetingToken is not always an array
When adding Activities to Scheduled Reminders, I came across a couple of warnings coming from core/CRM/Utils/Token.php. (https://lab.civicrm.org/dev/core/blob/master/CRM/Utils/Token.php)
Notice: Undefined index: contact in plugins/civicrm/civicrm/CRM/Utils/Token.php on line 1457
Warning: array_diff(): Argument #1 is not an array in plugins/civicrm/civicrm/CRM/Utils/Token.php on line 1457
According to line 1376, $greetingTokens is not necessarily expected to be an array, but lines 1454 and 1457 do expect it to be an array. Line 1407 looks like it might create an array for $greetingTokens, if you get there. Wrapping if statements around 1454 and 1457 so they look like below does remove the warnings:
// Remove null contact fields from $greetingTokens
if (!empty($greetingTokens) && array_key_exists('contact', $greetingTokens)) {
$greetingTokens['contact'] = array_diff($greetingTokens['contact'], $nullFields);
}
// Also remove them from $tokenString
if (!empty($greetingTokens) && array_key_exists('contact', $greetingTokensOriginal)) {
$removedTokens = array_diff($greetingTokensOriginal['contact'], $greetingTokens['contact']);
}
However, I expect that's not the correct answer. It seems like $greetingTokens should be treated as an array throughout the file, and an "if" test should be done at the top, converting it to an array if the test is false. However, I'm afraid that's deeper than I can wade.
Originally found while also attempting to diagnose #58 (closed)