token-8.x-1.x-dev/tests/modules/token_module_test/token_module_test.module

tests/modules/token_module_test/token_module_test.module
<?php

/**
 * @file
 * Helper module for token tests.
 */

use Drupal\node\NodeInterface;

/**
 * Implements hook_page_attachments().
 */
function token_module_test_page_attachments() {
  if ($debug = \Drupal::state()->get('token_page_tokens', [])) {
    $debug += ['tokens' => [], 'data' => [], 'options' => []];
    foreach (array_keys($debug['tokens']) as $token) {
      $debug['values'][$token] = \Drupal::token()->replace($token, $debug['data'], $debug['options']);
    }
    \Drupal::state()->set('token_page_tokens', $debug);
  }
}

/**
 * Implements hook_ENTITY_TYPE_presave for Node entities.
 */
function token_module_test_node_presave(NodeInterface $node) {
  // Transform tokens in the body.
  // @see \Drupal\token\Tests\TokenMenuTest::testMenuTokens()
  if ($node->hasField('body') && $node->get('body')->value) {
    $node->body->value = \Drupal::token()
      ->replace($node->body->value, ['node' => $node]);
  }
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc