5 * Helper module for token tests.
7 use Drupal\node\NodeInterface;
10 * Implements hook_page_attachments().
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']);
18 \Drupal::state()->set('token_page_tokens', $debug);
23 * Implements hook_ENTITY_TYPE_presave for Node entities.
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]);