From 7c0d73354402ffcdd5f70b9868b084567c7dbbd8 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 10 Aug 2021 16:45:21 -0700 Subject: [PATCH] ActionSchedule - Set locale during mail hooks / delivery / etc From a core POV, this should be unnecessary. And I'm not sure that it's a good idea for contrib to assume that the locale has been set to the email receipient. (It probably isn't done that way in some contexts.) Never-the-less, this should provide greater continuity with the pre-existing behavior. If anyone, say, uses `Hook::alterMail()` to append a translated footer, then it should continue to work in the same way as before. --- CRM/Core/BAO/ActionSchedule.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CRM/Core/BAO/ActionSchedule.php b/CRM/Core/BAO/ActionSchedule.php index 00ac176a98..d77feae933 100644 --- a/CRM/Core/BAO/ActionSchedule.php +++ b/CRM/Core/BAO/ActionSchedule.php @@ -282,6 +282,9 @@ FROM civicrm_action_schedule cas } foreach ($tokenProcessor->evaluate()->getRows() as $tokenRow) { + // It's possible, eg, that sendReminderEmail fires Hook::alterMailParams() and that some listener use ts(). + $swapLocale = empty($row->context['locale']) ? NULL : \CRM_Utils_AutoClean::swapLocale($row->context['locale']); + if ($actionSchedule->mode === 'SMS' || $actionSchedule->mode === 'User_Preference') { CRM_Utils_Array::extend($errors, self::sendReminderSms($tokenRow, $actionSchedule, $dao->contactID)); } @@ -294,6 +297,8 @@ FROM civicrm_action_schedule cas $caseID = empty($dao->case_id) ? NULL : $dao->case_id; CRM_Core_BAO_ActionSchedule::createMailingActivity($tokenRow, $mapping, $dao->contactID, $dao->entityID, $caseID); } + + unset($swapLocale); } } catch (\Civi\Token\TokenException $e) { -- 2.25.1