(REF) TokenCompatSubscriber - Simplify expression that replaces unknown tokens
authorTim Otten <totten@civicrm.org>
Thu, 23 Sep 2021 00:25:45 +0000 (17:25 -0700)
committerTim Otten <totten@civicrm.org>
Thu, 23 Sep 2021 00:26:13 +0000 (17:26 -0700)
Additionally, this uses the regex from `TokenProcessor` instead of the regex from `CRM_Utils_Token`.
These differ in whether they capture the '|filter' expressions.

Civi/Token/TokenCompatSubscriber.php

index bef111009a227aec508d6cfcea0671baaa798315..3b49684471efeeb4c30810dafae6a5fb54251a48 100644 (file)
@@ -414,17 +414,10 @@ class TokenCompatSubscriber implements EventSubscriberInterface {
    */
   public function onRender(TokenRenderEvent $e): void {
     $useSmarty = !empty($e->context['smarty']);
-    $remainingTokens = \CRM_Utils_Token::getTokens($e->string);
-
-    if ($remainingTokens) {
-      foreach ($remainingTokens as $part1 => $part2) {
-        $e->string = preg_replace(
-          '/(?<!\{|\\\\)\{' . $part1 . '\.([\w]+(:|\.)?\w*(\-[\w\s]+)?)\}(?!\})/',
-          '',
-          $e->string
-        );
-      }
-    }
+    $e->string = $e->getTokenProcessor()->visitTokens($e->string, function() {
+      // For historical consistency, we filter out unrecognized tokens.
+      return '';
+    });
 
     if ($useSmarty) {
       $smartyVars = [];