Version 1
[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 use Drupal\node\NodeInterface;
8
9 /**
10  * Implements hook_page_attachments().
11  */
12 function token_module_test_page_attachments() {
13   if ($debug = \Drupal::state()->get('token_page_tokens', array())) {
14     $debug += array('tokens' => array(), 'data' => array(), 'options' => array());
15     foreach (array_keys($debug['tokens']) as $token) {
16       $debug['values'][$token] = \Drupal::token()->replace($token, $debug['data'], $debug['options']);
17     }
18     \Drupal::state()->set('token_page_tokens', $debug);
19   }
20 }
21
22 /**
23  * Implements hook_ENTITY_TYPE_presave for Node entities.
24  */
25 function token_module_test_node_presave(NodeInterface $node) {
26   // Transform tokens in the body.
27   // @see \Drupal\token\Tests\TokenMenuTest::testMenuTokens()
28   if ($node->hasField('body')) {
29     $node->body->value = \Drupal::token()
30       ->replace($node->body->value, ['node' => $node]);
31   }
32 }