Steps to reproduce
Execute the following code without specifying the clear option:
$node = \Drupal\node\Entity\Node::load($nid);
$result = \Drupal::service('token')->replace(
'[node:field_custom|node:title]',
['node' => $node]
);
Expected Result: The token should be replaced by the corresponding value (e.g., the node title).
Actual Result: The output is the literal string "[node:field_custom]".
Now, execute the code with the ['clear' => true] option:
$node = \Drupal\node\Entity\Node::load($nid);
$result = \Drupal::service('token')->replace(
'[node:field_custom|node:title]',
['node' => $node],
['clear' => true]
);
Expected and Actual Result: The output is the correct node title.
Impact:
This behavior indicates that the token_or module only processes the token replacement correctly when the clear option is explicitly set to true. Without this flag, the service fails to substitute the token values as expected, which could lead to inconsistencies and confusion in environments relying on default behavior.
Issue fork token_or-3519448
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
6run0 commentedComment #5
pianomansam commented@6run0 thank you for the bug report and issue fork with a potential fix. In order for it to be considered, please add tests that demonstrate both the bug and the fix.
Comment #6
tiago commentedHey yall,
I’m getting an issue when using [3519448-tokenor-module-fails] to send Twig-based mail templates via Symfony Mailer: the HTML comments in my templates are being stripped out entirely.
What I’m seeing
Any HTML comment of the form
<!--[if mso | IE]>…<![endif]-->is picked up by the token detector and removed from the rendered message. For example, a snippet like:is ending up as:
Where's the problem
I think the problem lies in the "src/TokenOrTokensPreAlter.php" specifically in "tokensPreAlter" function as shown bellow:
preg_match_all("/\[[^\[\]]+\]/", $text, $matches);identifies them as tokensstrpos($match, '|') !== FALSEidentifies them as a token_orThanks,
TM
Comment #7
pianomansam commented@tiage thanks for the feedback on this issue. Feel free to create a separate issue branch and come up with a solution.
Comment #10
lolgm commentedI’ve added tests to demonstrate the problem.
Two functional tests in
TokenOrWebformFunctionalBrokenTestwere updated to reflect the expected behavior.Comment #12
pianomansam commented@lolgm thanks for the tests. With those passing, I've gone ahead and merged this into dev.
Comment #13
pianomansam commentedReleased in v2.3.2