Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / token / tests / modules / token_module_test / token_module_test.module
1 <?php
2
3 /**
4  * @file
5  * Helper module for token tests.
6  */
7
8 use Drupal\node\NodeInterface;
9
10 /**
11  * Implements hook_page_attachments().
12  */
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']);
18     }
19     \Drupal::state()->set('token_page_tokens', $debug);
20   }
21 }
22
23 /**
24  * Implements hook_ENTITY_TYPE_presave for Node entities.
25  */
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]);
32   }
33 }