From d4cc12a83bfb4fb1be56f0bceff111372aed9903 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 7 Sep 2023 07:58:49 +1200 Subject: [PATCH] dev/core#4551 Fix escaping on token event.title --- CRM/Core/EntityTokens.php | 12 ++++++++++++ CRM/Event/Tokens.php | 7 ++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CRM/Core/EntityTokens.php b/CRM/Core/EntityTokens.php index a5e80be223..1fb8bcebc5 100644 --- a/CRM/Core/EntityTokens.php +++ b/CRM/Core/EntityTokens.php @@ -141,6 +141,18 @@ class CRM_Core_EntityTokens extends AbstractTokenSubscriber { $row->format('text/plain')->tokens($entity, $field, (string) $fieldValue); } + /** + * Is the text stored in html format. + * + * @param string $fieldName + * + * @return bool + */ + public function isHTMLTextField(string $fieldName): bool { + $metadata = $this->getMetadataForField($fieldName); + return ($this->getMetadataForField($fieldName)['input_type'] ?? NULL) === 'RichTextEditor'; + } + /** * Metadata about the entity fields. * diff --git a/CRM/Event/Tokens.php b/CRM/Event/Tokens.php index 4f1c0fe65d..009bcfaaaa 100644 --- a/CRM/Event/Tokens.php +++ b/CRM/Event/Tokens.php @@ -234,7 +234,12 @@ class CRM_Event_Tokens extends CRM_Core_EntityTokens { $tokens[$fieldName]['text/html'] = CRM_Core_BAO_CustomField::displayValue($value, $fieldSpec['custom_field_id']); } else { - $tokens[$fieldName]['text/html'] = $event[$fieldName]; + if ($this->isHTMLTextField($fieldName)) { + $tokens[$fieldName]['text/html'] = $event[$fieldName]; + } + else { + $tokens[$fieldName]['text/plain'] = $event[$fieldName]; + } } } } -- 2.25.1