token_or module fails without explicit 'clear' option in token service replacement

Created on 16 April 2025, 4 days ago

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_title_for_yandex_direct|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.

🐛 Bug report
Status

Active

Version

2.3

Component

Code

Created by

🇷🇺Russia 6RUN0

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024