5 * Helper module for token tests.
8 use Drupal\node\NodeInterface;
11 * Implements hook_page_attachments().
13 function token_module_test_page_attachments() {
14 if ($debug = \Drupal::state()->get('token_page_tokens', [])) {
15 $debug += ['tokens' => [], 'data' => [], 'options' => []];
16 foreach (array_keys($debug['tokens']) as $token) {
17 $debug['values'][$token] = \Drupal::token()->replace($token, $debug['data'], $debug['options']);
19 \Drupal::state()->set('token_page_tokens', $debug);
24 * Implements hook_ENTITY_TYPE_presave for Node entities.
26 function token_module_test_node_presave(NodeInterface $node) {
27 // Transform tokens in the body.
28 // @see \Drupal\token\Tests\TokenMenuTest::testMenuTokens()
29 if ($node->hasField('body')) {
30 $node->body->value = \Drupal::token()
31 ->replace($node->body->value, ['node' => $node]);