From 5d1d65468aabe27b93e813852e192ff96b8ee229 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 6 Sep 2021 20:26:04 +1200 Subject: [PATCH] Block submission with token format that is ambiguous with the processor --- CRM/Contact/Form/Task/EmailTrait.php | 22 ++++++++++++++++++++++ CRM/Core/Form/Task/PDFLetterCommon.php | 14 +++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/CRM/Contact/Form/Task/EmailTrait.php b/CRM/Contact/Form/Task/EmailTrait.php index 2e78e168a4..d233dff33b 100644 --- a/CRM/Contact/Form/Task/EmailTrait.php +++ b/CRM/Contact/Form/Task/EmailTrait.php @@ -352,6 +352,7 @@ trait CRM_Contact_Form_Task_EmailTrait { CRM_Campaign_BAO_Campaign::addCampaign($this); $this->addFormRule([__CLASS__, 'saveTemplateFormRule'], $this); + $this->addFormRule([__CLASS__, 'deprecatedTokensFormRule'], $this); CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'templates/CRM/Contact/Form/Task/EmailCommon.js', 0, 'html-header'); } @@ -683,6 +684,27 @@ trait CRM_Contact_Form_Task_EmailTrait { return empty($errors) ? TRUE : $errors; } + /** + * Prevent submission of deprecated tokens. + * + * @param array $fields + * + * @return bool|string[] + */ + public static function deprecatedTokensFormRule(array $fields) { + $deprecatedTokens = [ + '{case.status_id}' => '{case.status_id:label}', + '{case.case_type_id}' => '{case.case_type_id:label}', + ]; + $tokenErrors = []; + foreach ($deprecatedTokens as $token => $replacement) { + if (strpos($fields['html_message'], $token) !== FALSE) { + $tokenErrors[] = ts('Token %1 is no longer supported - use %2 instead', [$token, $replacement]); + } + } + return empty($tokenErrors) ? TRUE : ['html_message' => implode('
', $tokenErrors)]; + } + /** * Get selected contribution IDs. * diff --git a/CRM/Core/Form/Task/PDFLetterCommon.php b/CRM/Core/Form/Task/PDFLetterCommon.php index 7fca6da789..b7762ccdc0 100644 --- a/CRM/Core/Form/Task/PDFLetterCommon.php +++ b/CRM/Core/Form/Task/PDFLetterCommon.php @@ -198,7 +198,19 @@ class CRM_Core_Form_Task_PDFLetterCommon { */ public static function formRule($fields, $files, $self) { $errors = []; - $template = CRM_Core_Smarty::singleton(); + $deprecatedTokens = [ + '{case.status_id}' => '{case.status_id:label}', + '{case.case_type_id}' => '{case.case_type_id:label}', + ]; + $tokenErrors = []; + foreach ($deprecatedTokens as $token => $replacement) { + if (strpos($fields['html_message'], $token) !== FALSE) { + $tokenErrors[] = ts('Token %1 is no longer supported - use %2 instead', [$token, $replacement]); + } + } + if (!empty($tokenErrors)) { + $errors['html_message'] = implode('
', $tokenErrors); + } // If user uploads non-document file other than odt/docx if (empty($fields['template']) && -- 2.25.1