diff --git a/src/Controller/TokenAutocompleteController.php b/src/Controller/TokenAutocompleteController.php
index a50da70..35b5a37 100644
--- a/src/Controller/TokenAutocompleteController.php
+++ b/src/Controller/TokenAutocompleteController.php
@@ -48,7 +48,7 @@ class TokenAutocompleteController extends ControllerBase {
public function autocomplete($token_type, $filter, Request $request) {
$filter = substr($filter, strrpos($filter, '['));
- $matches = array();
+ $matches = [];
if (!Unicode::strlen($filter)) {
$matches["[{$token_type}:"] = 0;
diff --git a/src/Routing/RouteSubscriber.php b/src/Routing/RouteSubscriber.php
index ae6815a..376b48f 100644
--- a/src/Routing/RouteSubscriber.php
+++ b/src/Routing/RouteSubscriber.php
@@ -68,7 +68,7 @@ class RouteSubscriber extends RouteSubscriberBase {
*/
public static function getSubscribedEvents() {
$events = parent::getSubscribedEvents();
- $events[RoutingEvents::ALTER] = array('onAlterRoutes', 100);
+ $events[RoutingEvents::ALTER] = ['onAlterRoutes', 100];
return $events;
}
}
diff --git a/src/Tests/TokenBlockTest.php b/src/Tests/TokenBlockTest.php
index 66e3025..ab304b3 100644
--- a/src/Tests/TokenBlockTest.php
+++ b/src/Tests/TokenBlockTest.php
@@ -21,38 +21,38 @@ class TokenBlockTest extends TokenTestBase {
/**
* {@inheritdoc}
*/
- public function setUp($modules = array()) {
+ public function setUp($modules = []) {
parent::setUp();
- $this->admin_user = $this->drupalCreateUser(array('access content', 'administer blocks'));
+ $this->admin_user = $this->drupalCreateUser(['access content', 'administer blocks']);
$this->drupalLogin($this->admin_user);
}
public function testBlockTitleTokens() {
$label = 'tokenblock';
- $bundle = BlockContentType::create(array(
+ $bundle = BlockContentType::create([
'id' => $label,
'label' => $label,
'revision' => FALSE
- ));
+ ]);
$bundle->save();
- $block_content = BlockContent::create(array(
+ $block_content = BlockContent::create([
'type' => $label,
'label' => '[current-page:title] block title',
'info' => 'Test token title block',
'body[value]' => 'This is the test token title block.',
- ));
+ ]);
$block_content->save();
- $block = $this->drupalPlaceBlock('block_content:' . $block_content->uuid(), array(
+ $block = $this->drupalPlaceBlock('block_content:' . $block_content->uuid(), [
'label' => '[user:name]',
- ));
+ ]);
$this->drupalGet($block->urlInfo());
// Ensure that the link to available tokens is present and correctly
// positioned.
$this->assertLink('Browse available tokens.');
$this->assertText('This field supports tokens. Browse available tokens.');
- $this->drupalPostForm(NULL, array(), t('Save block'));
+ $this->drupalPostForm(NULL, [], t('Save block'));
// Ensure token validation is working on the block.
$this->assertText('Title is using the following invalid tokens: [user:name].');
@@ -63,8 +63,8 @@ class TokenBlockTest extends TokenTestBase {
$block->save();
// Ensure that tokens are not double-escaped when output as a block title.
- $this->drupalCreateContentType(array('type' => 'page'));
- $node = $this->drupalCreateNode(array('title' => "Site's first node"));
+ $this->drupalCreateContentType(['type' => 'page']);
+ $node = $this->drupalCreateNode(['title' => "Site's first node"]);
$this->drupalGet('node/' . $node->id());
// The apostraphe should only be escaped once.
$this->assertRaw("Site's first node block title");
diff --git a/src/Tests/TokenCurrentPageTest.php b/src/Tests/TokenCurrentPageTest.php
index cd8ac37..f54cbe5 100644
--- a/src/Tests/TokenCurrentPageTest.php
+++ b/src/Tests/TokenCurrentPageTest.php
@@ -16,19 +16,19 @@ class TokenCurrentPageTest extends TokenTestBase {
*
* @var array
*/
- public static $modules = array('node');
+ public static $modules = ['node'];
function testCurrentPageTokens() {
- $tokens = array(
+ $tokens = [
'[current-page:title]' => t('Log in'),
- '[current-page:url]' => Url::fromRoute('user.login', [], array('absolute' => TRUE))->toString(),
- '[current-page:url:absolute]' => Url::fromRoute('user.login', [], array('absolute' => TRUE))->toString(),
+ '[current-page:url]' => Url::fromRoute('user.login', [], ['absolute' => TRUE])->toString(),
+ '[current-page:url:absolute]' => Url::fromRoute('user.login', [], ['absolute' => TRUE])->toString(),
'[current-page:url:relative]' => Url::fromRoute('user.login')->toString(),
'[current-page:url:path]' => '/user/login',
'[current-page:url:args:value:0]' => 'user',
'[current-page:url:args:value:1]' => 'login',
'[current-page:url:args:value:2]' => NULL,
- '[current-page:url:unaliased]' => Url::fromRoute('user.login', [], array('absolute' => TRUE, 'alias' => TRUE))->toString(),
+ '[current-page:url:unaliased]' => Url::fromRoute('user.login', [], ['absolute' => TRUE, 'alias' => TRUE])->toString(),
'[current-page:page-number]' => 1,
'[current-page:query:foo]' => NULL,
'[current-page:query:bar]' => NULL,
@@ -36,20 +36,20 @@ class TokenCurrentPageTest extends TokenTestBase {
'[current-page:arg:0]' => 'user',
'[current-page:arg:1]' => 'login',
'[current-page:arg:2]' => NULL,
- );
+ ];
$this->assertPageTokens('user/login', $tokens);
- $this->drupalCreateContentType(array('type' => 'page'));
- $node = $this->drupalCreateNode(array('title' => 'Node title', 'path' => array('alias' => '/node-alias')));
- $tokens = array(
+ $this->drupalCreateContentType(['type' => 'page']);
+ $node = $this->drupalCreateNode(['title' => 'Node title', 'path' => ['alias' => '/node-alias']]);
+ $tokens = [
'[current-page:title]' => 'Node title',
- '[current-page:url]' => $node->url('canonical', array('absolute' => TRUE)),
- '[current-page:url:absolute]' => $node->url('canonical', array('absolute' => TRUE)),
+ '[current-page:url]' => $node->url('canonical', ['absolute' => TRUE]),
+ '[current-page:url:absolute]' => $node->url('canonical', ['absolute' => TRUE]),
'[current-page:url:relative]' => $node->url(),
'[current-page:url:alias]' => '/node-alias',
'[current-page:url:args:value:0]' => 'node-alias',
'[current-page:url:args:value:1]' => NULL,
- '[current-page:url:unaliased]' => $node->url('canonical', array('absolute' => TRUE, 'alias' => TRUE)),
+ '[current-page:url:unaliased]' => $node->url('canonical', ['absolute' => TRUE, 'alias' => TRUE]),
'[current-page:url:unaliased:args:value:0]' => 'node',
'[current-page:url:unaliased:args:value:1]' => $node->id(),
'[current-page:url:unaliased:args:value:2]' => NULL,
@@ -60,7 +60,7 @@ class TokenCurrentPageTest extends TokenTestBase {
'[current-page:arg:0]' => 'node',
'[current-page:arg:1]' => 1,
'[current-page:arg:2]' => NULL,
- );
- $this->assertPageTokens("/node/{$node->id()}", $tokens, array(), array('url_options' => array('query' => array('foo' => 'bar'))));
+ ];
+ $this->assertPageTokens("/node/{$node->id()}", $tokens, [], ['url_options' => ['query' => ['foo' => 'bar']]]);
}
}
diff --git a/src/Tests/TokenFieldUiTest.php b/src/Tests/TokenFieldUiTest.php
index f7983e7..a96e324 100644
--- a/src/Tests/TokenFieldUiTest.php
+++ b/src/Tests/TokenFieldUiTest.php
@@ -41,50 +41,50 @@ class TokenFieldUiTest extends TokenTestBase {
]);
$node_type->save();
- entity_create('field_storage_config', array(
+ entity_create('field_storage_config', [
'field_name' => 'field_body',
'entity_type' => 'node',
'type' => 'text_with_summary',
- ))->save();
- entity_create('field_config', array(
+ ])->save();
+ entity_create('field_config', [
'field_name' => 'field_body',
'label' => 'Body',
'entity_type' => 'node',
'bundle' => 'article',
- ))->save();
- entity_create('field_storage_config', array(
+ ])->save();
+ entity_create('field_storage_config', [
'field_name' => 'field_image',
'entity_type' => 'node',
'type' => 'image',
- ))->save();
- entity_create('field_config', array(
+ ])->save();
+ entity_create('field_config', [
'field_name' => 'field_image',
'label' => 'Image',
'entity_type' => 'node',
'bundle' => 'article',
- ))->save();
- entity_create('field_storage_config', array(
+ ])->save();
+ entity_create('field_storage_config', [
'field_name' => 'field_image_2',
'entity_type' => 'node',
'type' => 'image',
- ))->save();
- entity_create('field_config', array(
+ ])->save();
+ entity_create('field_config', [
'field_name' => 'field_image_2',
'label' => 'Image 2',
'entity_type' => 'node',
'bundle' => 'article',
- ))->save();
- entity_create('field_storage_config', array(
+ ])->save();
+ entity_create('field_storage_config', [
'field_name' => 'multivalued_field_image',
'entity_type' => 'node',
'type' => 'image',
- ))->save();
- entity_create('field_config', array(
+ ])->save();
+ entity_create('field_config', [
'field_name' => 'multivalued_field_image',
'label' => 'Multivalued field image',
'entity_type' => 'node',
'bundle' => 'article',
- ))->save();
+ ])->save();
entity_get_form_display('node', 'article', 'default')
->setComponent('field_body', [
diff --git a/src/Tests/TokenMenuTest.php b/src/Tests/TokenMenuTest.php
index b9eb920..fd314d3 100644
--- a/src/Tests/TokenMenuTest.php
+++ b/src/Tests/TokenMenuTest.php
@@ -35,11 +35,11 @@ class TokenMenuTest extends TokenTestBase {
// Make sure we have a body field on the node type.
$this->drupalCreateContentType(['type' => 'page']);
// Add a menu.
- $menu = entity_create('menu', array(
+ $menu = entity_create('menu', [
'id' => 'main-menu',
'label' => 'Main menu',
'description' => 'The Main menu is used on many sites to show the major sections of the site, often in a top navigation bar.',
- ));
+ ]);
$menu->save();
// Place the menu block.
@@ -47,25 +47,25 @@ class TokenMenuTest extends TokenTestBase {
// Add a root link.
/** @var \Drupal\menu_link_content\Plugin\Menu\MenuLinkContent $root_link */
- $root_link = entity_create('menu_link_content', array(
+ $root_link = entity_create('menu_link_content', [
'link' => ['uri' => 'internal:/admin'],
'title' => 'Administration',
'menu_name' => 'main-menu',
- ));
+ ]);
$root_link->save();
// Add another link with the root link as the parent.
/** @var \Drupal\menu_link_content\Plugin\Menu\MenuLinkContent $parent_link */
- $parent_link = entity_create('menu_link_content', array(
+ $parent_link = entity_create('menu_link_content', [
'link' => ['uri' => 'internal:/admin/config'],
'title' => 'Configuration',
'menu_name' => 'main-menu',
'parent' => $root_link->getPluginId(),
- ));
+ ]);
$parent_link->save();
// Test menu link tokens.
- $tokens = array(
+ $tokens = [
'id' => $parent_link->getPluginId(),
'title' => 'Configuration',
'menu' => 'Main menu',
@@ -73,13 +73,13 @@ class TokenMenuTest extends TokenTestBase {
'menu:machine-name' => $menu->id(),
'menu:description' => 'The Main menu is used on many sites to show the major sections of the site, often in a top navigation bar.',
'menu:menu-link-count' => '2',
- 'menu:edit-url' => Url::fromRoute('entity.menu.edit_form', ['menu' => 'main-menu'], array('absolute' => TRUE))->toString(),
- 'url' => Url::fromRoute('system.admin_config', [], array('absolute' => TRUE))->toString(),
- 'url:absolute' => Url::fromRoute('system.admin_config', [], array('absolute' => TRUE))->toString(),
- 'url:relative' => Url::fromRoute('system.admin_config', [], array('absolute' => FALSE))->toString(),
+ 'menu:edit-url' => Url::fromRoute('entity.menu.edit_form', ['menu' => 'main-menu'], ['absolute' => TRUE])->toString(),
+ 'url' => Url::fromRoute('system.admin_config', [], ['absolute' => TRUE])->toString(),
+ 'url:absolute' => Url::fromRoute('system.admin_config', [], ['absolute' => TRUE])->toString(),
+ 'url:relative' => Url::fromRoute('system.admin_config', [], ['absolute' => FALSE])->toString(),
'url:path' => '/admin/config',
'url:alias' => '/admin/config',
- 'edit-url' => Url::fromRoute('entity.menu_link_content.canonical', ['menu_link_content' => $parent_link->id()], array('absolute' => TRUE))->toString(),
+ 'edit-url' => Url::fromRoute('entity.menu_link_content.canonical', ['menu_link_content' => $parent_link->id()], ['absolute' => TRUE])->toString(),
'parent' => 'Administration',
'parent:id' => $root_link->getPluginId(),
'parent:title' => 'Administration',
@@ -92,8 +92,8 @@ class TokenMenuTest extends TokenTestBase {
'root:id' => $root_link->getPluginId(),
'root:parent' => NULL,
'root:root' => NULL,
- );
- $this->assertTokens('menu-link', array('menu-link' => $parent_link), $tokens);
+ ];
+ $this->assertTokens('menu-link', ['menu-link' => $parent_link], $tokens);
// Add a node.
$node = $this->drupalCreateNode();
@@ -103,16 +103,16 @@ class TokenMenuTest extends TokenTestBase {
// Add a node menu link.
/** @var \Drupal\menu_link_content\Plugin\Menu\MenuLinkContent $node_link */
- $node_link = entity_create('menu_link_content', array(
+ $node_link = entity_create('menu_link_content', [
'link' => ['uri' =>'entity:node/' . $node->id()],
'title' => 'Node link',
'parent' => $parent_link->getPluginId(),
'menu_name' => 'main-menu',
- ));
+ ]);
$node_link->save();
// Test [node:menu] tokens.
- $tokens = array(
+ $tokens = [
'menu-link' => 'Node link',
'menu-link:id' => $node_link->getPluginId(),
'menu-link:title' => 'Node link',
@@ -127,12 +127,12 @@ class TokenMenuTest extends TokenTestBase {
'menu-link:parents:keys' => $root_link->getPluginId() . ', ' . $parent_link->getPluginId(),
'menu-link:root' => 'Administration',
'menu-link:root:id' => $root_link->getPluginId(),
- );
- $this->assertTokens('node', array('node' => $node), $tokens);
+ ];
+ $this->assertTokens('node', ['node' => $node], $tokens);
// Reload the node which will not have $node->menu defined and re-test.
$loaded_node = Node::load($node->id());
- $this->assertTokens('node', array('node' => $loaded_node), $tokens);
+ $this->assertTokens('node', ['node' => $loaded_node], $tokens);
// Regression test for http://drupal.org/node/1317926 to ensure the
// original node object is not changed when calling menu_node_prepare().
@@ -148,11 +148,11 @@ class TokenMenuTest extends TokenTestBase {
'access administration pages',
]));
// Setup node type menu options.
- $edit = array(
+ $edit = [
'menu_options[main-menu]' => 1,
'menu_options[main]' => 1,
'menu_parent' => 'main-menu:',
- );
+ ];
$this->drupalPostForm('admin/structure/types/manage/page', $edit, t('Save content type'));
// Use a menu-link token in the body.
@@ -306,7 +306,7 @@ class TokenMenuTest extends TokenTestBase {
]);
$node_type->save();
- $permissions = array(
+ $permissions = [
'access administration pages',
'administer content translation',
'administer content types',
@@ -316,18 +316,18 @@ class TokenMenuTest extends TokenTestBase {
'edit any article content',
'translate any entity',
'administer menu',
- );
+ ];
$this->drupalLogin($this->drupalCreateUser($permissions));
// Enable translation for articles and menu links.
$this->drupalGet('admin/config/regional/content-language');
- $edit = array(
+ $edit = [
'entity_types[node]' => TRUE,
'entity_types[menu_link_content]' => TRUE,
'settings[node][article][translatable]' => TRUE,
'settings[node][article][fields][title]' => TRUE,
'settings[menu_link_content][menu_link_content][translatable]' => TRUE,
- );
+ ];
$this->drupalPostForm(NULL, $edit, t('Save configuration'));
$this->assertText('Settings successfully updated.');
@@ -411,10 +411,10 @@ class TokenMenuTest extends TokenTestBase {
// - parent
// - child-1
// - child-1-1
- Menu::create(array(
+ Menu::create([
'id' => 'menu_test',
'label' => 'Test menu',
- ))->save();
+ ])->save();
$base_options = [
'provider' => 'menu_test',
'menu_name' => 'menu_test',
diff --git a/src/Tests/TokenTestBase.php b/src/Tests/TokenTestBase.php
index 29c1ac3..814ba77 100644
--- a/src/Tests/TokenTestBase.php
+++ b/src/Tests/TokenTestBase.php
@@ -16,6 +16,6 @@ abstract class TokenTestBase extends WebTestBase {
*
* @var array
*/
- public static $modules = array('path', 'token', 'token_module_test');
+ public static $modules = ['path', 'token', 'token_module_test'];
}
diff --git a/src/Tests/TokenTestTrait.php b/src/Tests/TokenTestTrait.php
index b37cae9..4715274 100644
--- a/src/Tests/TokenTestTrait.php
+++ b/src/Tests/TokenTestTrait.php
@@ -11,57 +11,57 @@ use Drupal\Core\Render\BubbleableMetadata;
*/
trait TokenTestTrait {
- function assertToken($type, array $data, $token, $expected, array $options = array()) {
- return $this->assertTokens($type, $data, array($token => $expected), $options);
+ function assertToken($type, array $data, $token, $expected, array $options = []) {
+ return $this->assertTokens($type, $data, [$token => $expected], $options);
}
- function assertTokens($type, array $data, array $tokens, array $options = array()) {
+ function assertTokens($type, array $data, array $tokens, array $options = []) {
$input = $this->mapTokenNames($type, array_keys($tokens));
$bubbleable_metadata = new BubbleableMetadata();
$replacements = \Drupal::token()->generate($type, $input, $data, $options, $bubbleable_metadata);
foreach ($tokens as $name => $expected) {
$token = $input[$name];
if (!isset($expected)) {
- $this->assertTrue(!isset($replacements[$token]), t("Token value for @token was not generated.", array('@type' => $type, '@token' => $token)));
+ $this->assertTrue(!isset($replacements[$token]), t("Token value for @token was not generated.", ['@type' => $type, '@token' => $token]));
}
elseif (!isset($replacements[$token])) {
- $this->fail(t("Token value for @token was not generated.", array('@type' => $type, '@token' => $token)));
+ $this->fail(t("Token value for @token was not generated.", ['@type' => $type, '@token' => $token]));
}
elseif (!empty($options['regex'])) {
- $this->assertTrue(preg_match('/^' . $expected . '$/', $replacements[$token]), t("Token value for @token was '@actual', matching regular expression pattern '@expected'.", array('@type' => $type, '@token' => $token, '@actual' => $replacements[$token], '@expected' => $expected)));
+ $this->assertTrue(preg_match('/^' . $expected . '$/', $replacements[$token]), t("Token value for @token was '@actual', matching regular expression pattern '@expected'.", ['@type' => $type, '@token' => $token, '@actual' => $replacements[$token], '@expected' => $expected]));
}
else {
- $this->assertEqual($replacements[$token], $expected, t("Token value for @token was '@actual', expected value '@expected'.", array('@type' => $type, '@token' => $token, '@actual' => $replacements[$token], '@expected' => $expected)));
+ $this->assertEqual($replacements[$token], $expected, t("Token value for @token was '@actual', expected value '@expected'.", ['@type' => $type, '@token' => $token, '@actual' => $replacements[$token], '@expected' => $expected]));
}
}
return $replacements;
}
- function mapTokenNames($type, array $tokens = array()) {
- $return = array();
+ function mapTokenNames($type, array $tokens = []) {
+ $return = [];
foreach ($tokens as $token) {
$return[$token] = "[$type:$token]";
}
return $return;
}
- function assertNoTokens($type, array $data, array $tokens, array $options = array()) {
+ function assertNoTokens($type, array $data, array $tokens, array $options = []) {
$input = $this->mapTokenNames($type, $tokens);
$bubbleable_metadata = new BubbleableMetadata();
$replacements = \Drupal::token()->generate($type, $input, $data, $options, $bubbleable_metadata);
foreach ($tokens as $name) {
$token = $input[$name];
- $this->assertTrue(!isset($replacements[$token]), t("Token value for @token was not generated.", array('@type' => $type, '@token' => $token)));
+ $this->assertTrue(!isset($replacements[$token]), t("Token value for @token was not generated.", ['@type' => $type, '@token' => $token]));
}
}
function saveAlias($source, $alias, $language = Language::LANGCODE_NOT_SPECIFIED) {
- $alias = array(
+ $alias = [
'source' => $source,
'alias' => $alias,
'language' => $language,
- );
+ ];
\Drupal::service('path.alias_storage')->save($alias['source'], $alias['alias']);
return $alias;
}
@@ -74,22 +74,22 @@ trait TokenTestTrait {
/**
* Make a page request and test for token generation.
*/
- function assertPageTokens($url, array $tokens, array $data = array(), array $options = array()) {
+ function assertPageTokens($url, array $tokens, array $data = [], array $options = []) {
if (empty($tokens)) {
return TRUE;
}
- $token_page_tokens = array(
+ $token_page_tokens = [
'tokens' => $tokens,
'data' => $data,
'options' => $options,
- );
+ ];
\Drupal::state()->set('token_page_tokens', $token_page_tokens);
- $options += array('url_options' => array());
+ $options += ['url_options' => []];
$this->drupalGet($url, $options['url_options']);
$this->refreshVariables();
- $result = \Drupal::state()->get('token_page_tokens', array());
+ $result = \Drupal::state()->get('token_page_tokens', []);
if (!isset($result['values']) || !is_array($result['values'])) {
return $this->fail('Failed to generate tokens.');
@@ -97,13 +97,13 @@ trait TokenTestTrait {
foreach ($tokens as $token => $expected) {
if (!isset($expected)) {
- $this->assertTrue(!isset($result['values'][$token]) || $result['values'][$token] === $token, t("Token value for @token was not generated.", array('@token' => $token)));
+ $this->assertTrue(!isset($result['values'][$token]) || $result['values'][$token] === $token, t("Token value for @token was not generated.", ['@token' => $token]));
}
elseif (!isset($result['values'][$token])) {
- $this->fail(t('Failed to generate token @token.', array('@token' => $token)));
+ $this->fail(t('Failed to generate token @token.', ['@token' => $token]));
}
else {
- $this->assertIdentical($result['values'][$token], (string) $expected, t("Token value for @token was '@actual', expected value '@expected'.", array('@token' => $token, '@actual' => $result['values'][$token], '@expected' => $expected)));
+ $this->assertIdentical($result['values'][$token], (string) $expected, t("Token value for @token was '@actual', expected value '@expected'.", ['@token' => $token, '@actual' => $result['values'][$token], '@expected' => $expected]));
}
}
}
diff --git a/src/Tests/TokenURLTest.php b/src/Tests/TokenURLTest.php
index 6241f3b..0a3bed0 100644
--- a/src/Tests/TokenURLTest.php
+++ b/src/Tests/TokenURLTest.php
@@ -16,7 +16,7 @@ class TokenURLTest extends TokenTestBase {
*
* @var array
*/
- public static $modules = array('node');
+ public static $modules = ['node'];
/**
* {@inheritdoc}
@@ -27,25 +27,25 @@ class TokenURLTest extends TokenTestBase {
}
function testURLTokens() {
- $url = new Url('entity.node.canonical', array('node' => 1));
- $tokens = array(
+ $url = new Url('entity.node.canonical', ['node' => 1]);
+ $tokens = [
'absolute' => $url->setAbsolute()->toString(),
'relative' => $url->setAbsolute(FALSE)->toString(),
'path' => '/first-node',
- 'brief' => preg_replace(array('!^https?://!', '!/$!'), '', $url->setAbsolute()->toString()),
+ 'brief' => preg_replace(['!^https?://!', '!/$!'], '', $url->setAbsolute()->toString()),
'args:value:0' => 'first-node',
'args:value:1' => NULL,
'args:value:N' => NULL,
'unaliased' => $url->setAbsolute()->setOption('alias', TRUE)->toString(),
'unaliased:relative' => $url->setAbsolute(FALSE)->setOption('alias', TRUE)->toString(),
'unaliased:path' => '/node/1',
- 'unaliased:brief' => preg_replace(array('!^https?://!', '!/$!'), '', $url->setAbsolute()->setOption('alias', TRUE)->toString()),
+ 'unaliased:brief' => preg_replace(['!^https?://!', '!/$!'], '', $url->setAbsolute()->setOption('alias', TRUE)->toString()),
'unaliased:args:value:0' => 'node',
'unaliased:args:value:1' => '1',
'unaliased:args:value:2' => NULL,
// Deprecated tokens.
'alias' => '/first-node',
- );
- $this->assertTokens('url', array('url' => new Url('entity.node.canonical', array('node' => 1))), $tokens);
+ ];
+ $this->assertTokens('url', ['url' => new Url('entity.node.canonical', ['node' => 1])], $tokens);
}
}
diff --git a/src/Tests/TokenUserTest.php b/src/Tests/TokenUserTest.php
index 2178c7e..f61c1a0 100644
--- a/src/Tests/TokenUserTest.php
+++ b/src/Tests/TokenUserTest.php
@@ -24,7 +24,7 @@ class TokenUserTest extends TokenTestBase {
*
* @var array
*/
- public static $modules = array('token_user_picture');
+ public static $modules = ['token_user_picture'];
/**
* {@inheritdoc}
@@ -49,7 +49,7 @@ class TokenUserTest extends TokenTestBase {
// Add a user picture to the account.
$image = current($this->drupalGetTestFiles('image'));
- $edit = array('files[user_picture_0]' => drupal_realpath($image->uri));
+ $edit = ['files[user_picture_0]' => drupal_realpath($image->uri)];
$this->drupalPostForm('user/' . $this->account->id() . '/edit', $edit, t('Save'));
$storage = \Drupal::entityTypeManager()->getStorage('user');
@@ -65,14 +65,14 @@ class TokenUserTest extends TokenTestBase {
];
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = \Drupal::service('renderer');
- $user_tokens = array(
+ $user_tokens = [
'picture' => $renderer->renderPlain($picture),
'picture:fid' => $this->account->user_picture->target_id,
'picture:size-raw' => 125,
'ip-address' => NULL,
'roles' => implode(', ', $this->account->getRoles()),
- );
- $this->assertTokens('user', array('user' => $this->account), $user_tokens);
+ ];
+ $this->assertTokens('user', ['user' => $this->account], $user_tokens);
// Remove the simpletest-created user role.
$roles = $this->account->getRoles();
@@ -84,27 +84,27 @@ class TokenUserTest extends TokenTestBase {
$storage->resetCache();
$this->account = $storage->load($this->account->id());
- $user_tokens = array(
+ $user_tokens = [
'picture' => NULL,
'picture:fid' => NULL,
'ip-address' => NULL,
'roles' => 'authenticated',
'roles:keys' => (string) DRUPAL_AUTHENTICATED_RID,
- );
- $this->assertTokens('user', array('user' => $this->account), $user_tokens);
+ ];
+ $this->assertTokens('user', ['user' => $this->account], $user_tokens);
// The ip address token should work for the current user token type.
- $tokens = array(
+ $tokens = [
'ip-address' => \Drupal::request()->getClientIp(),
- );
- $this->assertTokens('current-user', array(), $tokens);
+ ];
+ $this->assertTokens('current-user', [], $tokens);
$anonymous = new AnonymousUserSession();
- $tokens = array(
+ $tokens = [
'roles' => 'anonymous',
'roles:keys' => (string) DRUPAL_ANONYMOUS_RID,
- );
- $this->assertTokens('user', array('user' => $anonymous), $tokens);
+ ];
+ $this->assertTokens('user', ['user' => $anonymous], $tokens);
}
public function testUserAccountSettings() {
diff --git a/src/Tests/Tree/TreeTest.php b/src/Tests/Tree/TreeTest.php
index ed1dd3c..7c72434 100644
--- a/src/Tests/Tree/TreeTest.php
+++ b/src/Tests/Tree/TreeTest.php
@@ -137,7 +137,7 @@ class TreeTest extends TokenTestBase {
protected function getTokenTreeUrl($options = []) {
$this->drupalGet('token_module_test/browse');
$this->assertTitle('Available Tokens | Drupal');
- $links = $this->xpath('//a[contains(@href, :href)]/@href', array(':href' => 'token/tree'));
+ $links = $this->xpath('//a[contains(@href, :href)]/@href', [':href' => 'token/tree']);
$link = $this->getAbsoluteUrl((string) current($links));
if (!empty($options)) {
$options = Json::encode($options);
diff --git a/src/Token.php b/src/Token.php
index 360ae35..b75af5a 100644
--- a/src/Token.php
+++ b/src/Token.php
@@ -65,9 +65,9 @@ class Token extends TokenBase implements TokenInterface {
}
$this->tokenInfo = $token_info;
- $this->cache->set($cache_id, $this->tokenInfo, CacheBackendInterface::CACHE_PERMANENT, array(
+ $this->cache->set($cache_id, $this->tokenInfo, CacheBackendInterface::CACHE_PERMANENT, [
static::TOKEN_INFO_CACHE_TAG,
- ));
+ ]);
}
}
@@ -136,7 +136,7 @@ class Token extends TokenBase implements TokenInterface {
*/
function getInvalidTokens($type, $tokens) {
$token_info = $this->getInfo();
- $invalid_tokens = array();
+ $invalid_tokens = [];
foreach ($tokens as $token => $full_token) {
if (isset($token_info['tokens'][$type][$token])) {
@@ -162,7 +162,7 @@ class Token extends TokenBase implements TokenInterface {
}
else {
// Recursively check the chained tokens.
- $sub_tokens = $this->findWithPrefix(array($token => $full_token), $parts[0]);
+ $sub_tokens = $this->findWithPrefix([$token => $full_token], $parts[0]);
$invalid_tokens = array_merge($invalid_tokens, $this->getInvalidTokens($sub_token_info['type'], $sub_tokens));
}
}
@@ -184,7 +184,7 @@ class Token extends TokenBase implements TokenInterface {
$valid_types = array_merge($valid_types, $this->getGlobalTokenTypes());
}
- $invalid_tokens = array();
+ $invalid_tokens = [];
$value_tokens = is_string($value) ? $this->scan($value) : $value;
foreach ($value_tokens as $type => $tokens) {
diff --git a/src/TreeBuilder.php b/src/TreeBuilder.php
index 80ebca2..935299d 100644
--- a/src/TreeBuilder.php
+++ b/src/TreeBuilder.php
@@ -61,12 +61,12 @@ class TreeBuilder implements TreeBuilderInterface {
$token_types = array_merge($token_types, $this->tokenService->getGlobalTokenTypes());
}
- $element = array(
+ $element = [
/*'#cache' => array(
'cid' => 'tree-rendered:' . hash('sha256', serialize(array('token_types' => $token_types, 'global_types' => NULL) + $variables)),
'tags' => array(Token::TOKEN_INFO_CACHE_TAG),
),*/
- );
+ ];
// @todo Find a way to use the render cache for this.
/*if ($cached_output = token_render_cache_get($element)) {
diff --git a/tests/modules/token_module_test/token_module_test.module b/tests/modules/token_module_test/token_module_test.module
index c263320..abcbd47 100644
--- a/tests/modules/token_module_test/token_module_test.module
+++ b/tests/modules/token_module_test/token_module_test.module
@@ -10,8 +10,8 @@ use Drupal\node\NodeInterface;
* Implements hook_page_attachments().
*/
function token_module_test_page_attachments() {
- if ($debug = \Drupal::state()->get('token_page_tokens', array())) {
- $debug += array('tokens' => array(), 'data' => array(), 'options' => array());
+ 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']);
}
diff --git a/tests/modules/token_module_test/token_module_test.tokens.inc b/tests/modules/token_module_test/token_module_test.tokens.inc
index ba8da53..3adf457 100644
--- a/tests/modules/token_module_test/token_module_test.tokens.inc
+++ b/tests/modules/token_module_test/token_module_test.tokens.inc
@@ -4,10 +4,10 @@
* Implements hook_token_info()
*/
function token_module_test_token_info() {
- $info['tokens']['node']['colons:in:name'] = array(
+ $info['tokens']['node']['colons:in:name'] = [
'name' => t('A test token with colons in the name'),
'description' => NULL,
- );
+ ];
return $info;
}
diff --git a/tests/src/Kernel/ArrayTest.php b/tests/src/Kernel/ArrayTest.php
index a7f83ae..35dbf24 100644
--- a/tests/src/Kernel/ArrayTest.php
+++ b/tests/src/Kernel/ArrayTest.php
@@ -11,8 +11,8 @@ class ArrayTest extends KernelTestBase {
function testArrayTokens() {
// Test a simple array.
- $array = array(0 => 'a', 1 => 'b', 2 => 'c', 4 => 'd');
- $tokens = array(
+ $array = [0 => 'a', 1 => 'b', 2 => 'c', 4 => 'd'];
+ $tokens = [
'first' => 'a',
'last' => 'd',
'value:0' => 'a',
@@ -27,19 +27,19 @@ class ArrayTest extends KernelTestBase {
'join' => 'abcd',
'join:, ' => 'a, b, c, d',
'join: ' => 'a b c d',
- );
- $this->assertTokens('array', array('array' => $array), $tokens);
+ ];
+ $this->assertTokens('array', ['array' => $array], $tokens);
// Test a mixed simple and render array.
// 2 => c, 0 => a, 4 => d, 1 => b
- $array = array(
+ $array = [
'#property' => 'value',
0 => 'a',
- 1 => array('#markup' => 'b', '#weight' => 0.01),
- 2 => array('#markup' => 'c', '#weight' => -10),
- 4 => array('#markup' => 'd', '#weight' => 0),
- );
- $tokens = array(
+ 1 => ['#markup' => 'b', '#weight' => 0.01],
+ 2 => ['#markup' => 'c', '#weight' => -10],
+ 4 => ['#markup' => 'd', '#weight' => 0],
+ ];
+ $tokens = [
'first' => 'c',
'last' => 'b',
'value:0' => 'a',
@@ -54,7 +54,7 @@ class ArrayTest extends KernelTestBase {
'join' => 'cadb',
'join:, ' => 'c, a, d, b',
'join: ' => 'c a d b',
- );
- $this->assertTokens('array', array('array' => $array), $tokens);
+ ];
+ $this->assertTokens('array', ['array' => $array], $tokens);
}
}
diff --git a/tests/src/Kernel/BookTest.php b/tests/src/Kernel/BookTest.php
index 67a13ee..de3125c 100644
--- a/tests/src/Kernel/BookTest.php
+++ b/tests/src/Kernel/BookTest.php
@@ -27,9 +27,9 @@ class BookTest extends KernelTestBase {
$this->installEntitySchema('user');
$this->installEntitySchema('node');
- $this->installSchema('book', array('book'));
- $this->installSchema('node', array('node_access'));
- $this->installConfig(array('node', 'book', 'field'));
+ $this->installSchema('book', ['book']);
+ $this->installSchema('node', ['node_access']);
+ $this->installConfig(['node', 'book', 'field']);
}
function testBookTokens() {
@@ -63,12 +63,12 @@ class BookTest extends KernelTestBase {
'book:root' => $book_title,
'book:root:nid' => $book->id(),
'book:root:title' => $book_title,
- 'book:root:url' => Url::fromRoute('entity.node.canonical', ['node' => $book->id()], array('absolute' => TRUE))->toString(),
+ 'book:root:url' => Url::fromRoute('entity.node.canonical', ['node' => $book->id()], ['absolute' => TRUE])->toString(),
'book:root:content-type' => 'Book page',
'book:parent' => null,
'book:parents' => null,
];
- $this->assertTokens('node', array('node' => $book), $tokens);
+ $this->assertTokens('node', ['node' => $book], $tokens);
$tokens = [
'nid' => $page1->id(),
@@ -77,15 +77,15 @@ class BookTest extends KernelTestBase {
'book:root' => $book_title,
'book:root:nid' => $book->id(),
'book:root:title' => $book_title,
- 'book:root:url' => Url::fromRoute('entity.node.canonical', ['node' => $book->id()], array('absolute' => TRUE))->toString(),
+ 'book:root:url' => Url::fromRoute('entity.node.canonical', ['node' => $book->id()], ['absolute' => TRUE])->toString(),
'book:root:content-type' => 'Book page',
'book:parent:nid' => $book->id(),
'book:parent:title' => $book_title,
- 'book:parent:url' => Url::fromRoute('entity.node.canonical', ['node' => $book->id()], array('absolute' => TRUE))->toString(),
+ 'book:parent:url' => Url::fromRoute('entity.node.canonical', ['node' => $book->id()], ['absolute' => TRUE])->toString(),
'book:parents:count' => 1,
'book:parents:join:/' => $book_title,
];
- $this->assertTokens('node', array('node' => $page1), $tokens);
+ $this->assertTokens('node', ['node' => $page1], $tokens);
$tokens = [
'nid' => $page2->id(),
@@ -94,14 +94,14 @@ class BookTest extends KernelTestBase {
'book:root' => $book_title,
'book:root:nid' => $book->id(),
'book:root:title' => $book_title,
- 'book:root:url' => Url::fromRoute('entity.node.canonical', ['node' => $book->id()], array('absolute' => TRUE))->toString(),
+ 'book:root:url' => Url::fromRoute('entity.node.canonical', ['node' => $book->id()], ['absolute' => TRUE])->toString(),
'book:root:content-type' => 'Book page',
'book:parent:nid' => $page1->id(),
'book:parent:title' => $page1->getTitle(),
- 'book:parent:url' => Url::fromRoute('entity.node.canonical', ['node' => $page1->id()], array('absolute' => TRUE))->toString(),
+ 'book:parent:url' => Url::fromRoute('entity.node.canonical', ['node' => $page1->id()], ['absolute' => TRUE])->toString(),
'book:parents:count' => 2,
'book:parents:join:/' => $book_title . '/' . $page1->getTitle(),
];
- $this->assertTokens('node', array('node' => $page2), $tokens);
+ $this->assertTokens('node', ['node' => $page2], $tokens);
}
}
diff --git a/tests/src/Kernel/CommentTest.php b/tests/src/Kernel/CommentTest.php
index 499f087..d3bc656 100644
--- a/tests/src/Kernel/CommentTest.php
+++ b/tests/src/Kernel/CommentTest.php
@@ -64,14 +64,14 @@ class CommentTest extends KernelTestBase {
// Fix http://example.com/index.php/comment/1 fails 'url:path' test.
$parent_comment_path = $parent_comment->url();
- $tokens = array(
+ $tokens = [
'url' => $parent_comment->urlInfo('canonical', ['fragment' => "comment-{$parent_comment->id()}"])->setAbsolute()->toString(),
'url:absolute' => $parent_comment->urlInfo('canonical', ['fragment' => "comment-{$parent_comment->id()}"])->setAbsolute()->toString(),
'url:relative' => $parent_comment->urlInfo('canonical', ['fragment' => "comment-{$parent_comment->id()}"])->toString(),
'url:path' => $parent_comment_path,
'parent:url:absolute' => NULL,
- );
- $this->assertTokens('comment', array('comment' => $parent_comment), $tokens);
+ ];
+ $this->assertTokens('comment', ['comment' => $parent_comment], $tokens);
$comment = Comment::create([
'entity_id' => $node->id(),
@@ -87,16 +87,16 @@ class CommentTest extends KernelTestBase {
$comment->save();
// Fix http://example.com/index.php/comment/1 fails 'url:path' test.
- $comment_path = Url::fromRoute('entity.comment.canonical', array('comment' => $comment->id()))->toString();
+ $comment_path = Url::fromRoute('entity.comment.canonical', ['comment' => $comment->id()])->toString();
- $tokens = array(
+ $tokens = [
'url' => $comment->urlInfo('canonical', ['fragment' => "comment-{$comment->id()}"])->setAbsolute()->toString(),
'url:absolute' => $comment->urlInfo('canonical', ['fragment' => "comment-{$comment->id()}"])->setAbsolute()->toString(),
'url:relative' => $comment->urlInfo('canonical', ['fragment' => "comment-{$comment->id()}"])->toString(),
'url:path' => $comment_path,
'parent:url:absolute' => $parent_comment->urlInfo('canonical', ['fragment' => "comment-{$parent_comment->id()}"])->setAbsolute()->toString(),
- );
- $this->assertTokens('comment', array('comment' => $comment), $tokens);
+ ];
+ $this->assertTokens('comment', ['comment' => $comment], $tokens);
}
}
diff --git a/tests/src/Kernel/DateTest.php b/tests/src/Kernel/DateTest.php
index c25bf03..eb62dff 100644
--- a/tests/src/Kernel/DateTest.php
+++ b/tests/src/Kernel/DateTest.php
@@ -25,11 +25,11 @@ class DateTest extends KernelTestBase {
}
function testDateTokens() {
- $tokens = array(
+ $tokens = [
'token_module_test' => '1984',
'invalid_format' => NULL,
- );
+ ];
- $this->assertTokens('date', array('date' => 453859200), $tokens);
+ $this->assertTokens('date', ['date' => 453859200], $tokens);
}
}
diff --git a/tests/src/Kernel/EntityTest.php b/tests/src/Kernel/EntityTest.php
index 7ff471d..2e539d8 100644
--- a/tests/src/Kernel/EntityTest.php
+++ b/tests/src/Kernel/EntityTest.php
@@ -59,15 +59,15 @@ class EntityTest extends KernelTestBase {
// that we still get the tokens replaced.
$vocabulary = entity_load('taxonomy_vocabulary', 'tags');
$term = $this->addTerm($vocabulary);
- $this->assertIdentical(\Drupal::token()->replace('[vocabulary:name]', array('taxonomy_vocabulary' => $vocabulary)), $vocabulary->label());
- $this->assertIdentical(\Drupal::token()->replace('[term:name][term:vocabulary:name]', array('taxonomy_term' => $term)), $term->label() . $vocabulary->label());
+ $this->assertIdentical(\Drupal::token()->replace('[vocabulary:name]', ['taxonomy_vocabulary' => $vocabulary]), $vocabulary->label());
+ $this->assertIdentical(\Drupal::token()->replace('[term:name][term:vocabulary:name]', ['taxonomy_term' => $term]), $term->label() . $vocabulary->label());
}
- function addTerm(VocabularyInterface $vocabulary, array $term = array()) {
- $term += array(
+ function addTerm(VocabularyInterface $vocabulary, array $term = []) {
+ $term += [
'name' => Unicode::strtolower($this->randomMachineName(5)),
'vid' => $vocabulary->id(),
- );
+ ];
$term = entity_create('taxonomy_term', $term);
$term->save();
return $term;
@@ -80,25 +80,25 @@ class EntityTest extends KernelTestBase {
$node = Node::create(['type' => 'page', 'title' => 'Original title']);
$node->save();
- $tokens = array(
+ $tokens = [
'nid' => $node->id(),
'title' => 'Original title',
'original' => NULL,
'original:nid' => NULL,
- );
- $this->assertTokens('node', array('node' => $node), $tokens);
+ ];
+ $this->assertTokens('node', ['node' => $node], $tokens);
// Emulate the original entity property that would be available from
// node_save() and change the title for the node.
$node->original = entity_load_unchanged('node', $node->id());
$node->title = 'New title';
- $tokens = array(
+ $tokens = [
'nid' => $node->id(),
'title' => 'New title',
'original' => 'Original title',
'original:nid' => $node->id(),
- );
- $this->assertTokens('node', array('node' => $node), $tokens);
+ ];
+ $this->assertTokens('node', ['node' => $node], $tokens);
}
}
diff --git a/tests/src/Kernel/FieldTest.php b/tests/src/Kernel/FieldTest.php
index de94699..a71bad4 100644
--- a/tests/src/Kernel/FieldTest.php
+++ b/tests/src/Kernel/FieldTest.php
@@ -191,12 +191,12 @@ class FieldTest extends KernelTestBase {
$language->save();
// Add a datetime field.
- $field_datetime_storage = FieldStorageConfig::create(array(
+ $field_datetime_storage = FieldStorageConfig::create([
'field_name' => 'field_datetime',
'type' => 'datetime',
'entity_type' => 'node',
- 'settings' => array('datetime_type' => DateTimeItem::DATETIME_TYPE_DATETIME),
- ));
+ 'settings' => ['datetime_type' => DateTimeItem::DATETIME_TYPE_DATETIME],
+ ]);
$field_datetime_storage->save();
$field_datetime = FieldConfig::create([
'field_storage' => $field_datetime_storage,
@@ -205,12 +205,12 @@ class FieldTest extends KernelTestBase {
$field_datetime->save();
// Add a daterange field.
- $field_daterange_storage = FieldStorageConfig::create(array(
+ $field_daterange_storage = FieldStorageConfig::create([
'field_name' => 'field_daterange',
'type' => 'daterange',
'entity_type' => 'node',
- 'settings' => array('datetime_type' => DateRangeItem::DATETIME_TYPE_DATETIME),
- ));
+ 'settings' => ['datetime_type' => DateRangeItem::DATETIME_TYPE_DATETIME],
+ ]);
$field_daterange_storage->save();
$field_daterange = FieldConfig::create([
'field_storage' => $field_daterange_storage,
diff --git a/tests/src/Kernel/FileTest.php b/tests/src/Kernel/FileTest.php
index 3a6a7fd..b888aed 100644
--- a/tests/src/Kernel/FileTest.php
+++ b/tests/src/Kernel/FileTest.php
@@ -14,7 +14,7 @@ class FileTest extends KernelTestBase {
*
* @var array
*/
- public static $modules = array('file');
+ public static $modules = ['file'];
/**
* {@inheritdoc}
@@ -26,30 +26,30 @@ class FileTest extends KernelTestBase {
function testFileTokens() {
// Create a test file object.
- $file = entity_create('file', array(
+ $file = entity_create('file', [
'fid' => 1,
'filename' => 'test.png',
'filesize' => 100,
'uri' => 'public://images/test.png',
'filemime' => 'image/png',
- ));
+ ]);
- $tokens = array(
+ $tokens = [
'basename' => 'test.png',
'extension' => 'png',
'size-raw' => 100,
- );
- $this->assertTokens('file', array('file' => $file), $tokens);
+ ];
+ $this->assertTokens('file', ['file' => $file], $tokens);
// Test a file with no extension and a fake name.
$file->filename = 'Test PNG image';
$file->uri = 'public://images/test';
- $tokens = array(
+ $tokens = [
'basename' => 'test',
'extension' => '',
'size-raw' => 100,
- );
- $this->assertTokens('file', array('file' => $file), $tokens);
+ ];
+ $this->assertTokens('file', ['file' => $file], $tokens);
}
}
diff --git a/tests/src/Kernel/NodeTest.php b/tests/src/Kernel/NodeTest.php
index e44b9ab..3c82706 100644
--- a/tests/src/Kernel/NodeTest.php
+++ b/tests/src/Kernel/NodeTest.php
@@ -48,52 +48,52 @@ class NodeTest extends KernelTestBase {
'type' => 'page',
'title' => 'Source Title',
'revision_log' => $this->randomMachineName(),
- 'path' => array('alias' => '/content/source-node')
+ 'path' => ['alias' => '/content/source-node']
]);
$page->save();
- $tokens = array(
+ $tokens = [
'log' => $page->revision_log->value,
'url:path' => '/content/source-node',
- 'url:absolute' => Url::fromRoute('entity.node.canonical', ['node' => $page->id()], array('absolute' => TRUE))->toString(),
- 'url:relative' => Url::fromRoute('entity.node.canonical', ['node' => $page->id()], array('absolute' => FALSE))->toString(),
+ 'url:absolute' => Url::fromRoute('entity.node.canonical', ['node' => $page->id()], ['absolute' => TRUE])->toString(),
+ 'url:relative' => Url::fromRoute('entity.node.canonical', ['node' => $page->id()], ['absolute' => FALSE])->toString(),
'url:unaliased:path' => "/node/{$page->id()}",
'content-type' => 'Basic page',
'content-type:name' => 'Basic page',
'content-type:machine-name' => 'page',
'content-type:description' => "Use basic pages for your static content, such as an 'About us' page.",
'content-type:node-count' => 1,
- 'content-type:edit-url' => Url::fromRoute('entity.node_type.edit_form', ['node_type' => 'page'], array('absolute' => TRUE))->toString(),
+ 'content-type:edit-url' => Url::fromRoute('entity.node_type.edit_form', ['node_type' => 'page'], ['absolute' => TRUE])->toString(),
'source:title' => 'Source Title',
// Deprecated tokens.
'type' => 'page',
'type-name' => 'Basic page',
'url:alias' => '/content/source-node',
- );
- $this->assertTokens('node', array('node' => $page), $tokens);
+ ];
+ $this->assertTokens('node', ['node' => $page], $tokens);
$article = Node::create([
'type' => 'article',
'title' => 'Source Title',
]);
$article->save();
- $tokens = array(
+ $tokens = [
'log' => '',
'url:path' => "/node/{$article->id()}",
- 'url:absolute' => Url::fromRoute('entity.node.canonical', ['node' => $article->id()], array('absolute' => TRUE))->toString(),
- 'url:relative' => Url::fromRoute('entity.node.canonical', ['node' => $article->id()], array('absolute' => FALSE))->toString(),
+ 'url:absolute' => Url::fromRoute('entity.node.canonical', ['node' => $article->id()], ['absolute' => TRUE])->toString(),
+ 'url:relative' => Url::fromRoute('entity.node.canonical', ['node' => $article->id()], ['absolute' => FALSE])->toString(),
'url:unaliased:path' => "/node/{$article->id()}",
'content-type' => 'Article',
'content-type:name' => 'Article',
'content-type:machine-name' => 'article',
'content-type:description' => "Use articles for time-sensitive content like news, press releases or blog posts.",
'content-type:node-count' => 1,
- 'content-type:edit-url' => Url::fromRoute('entity.node_type.edit_form', ['node_type' => 'article'], array('absolute' => TRUE))->toString(),
+ 'content-type:edit-url' => Url::fromRoute('entity.node_type.edit_form', ['node_type' => 'article'], ['absolute' => TRUE])->toString(),
'source:title' => 'Source Title',
// Deprecated tokens.
'type' => 'article',
'type-name' => 'Article',
'url:alias' => "/node/{$article->id()}",
- );
- $this->assertTokens('node', array('node' => $article), $tokens);
+ ];
+ $this->assertTokens('node', ['node' => $article], $tokens);
}
}
diff --git a/tests/src/Kernel/RandomTest.php b/tests/src/Kernel/RandomTest.php
index a4b0930..35d7cd4 100644
--- a/tests/src/Kernel/RandomTest.php
+++ b/tests/src/Kernel/RandomTest.php
@@ -10,16 +10,16 @@ namespace Drupal\Tests\token\Kernel;
class RandomTest extends KernelTestBase {
function testRandomTokens() {
- $tokens = array(
+ $tokens = [
'number' => '[0-9]{1,}',
'hash:md5' => '[0-9a-f]{32}',
'hash:sha1' => '[0-9a-f]{40}',
'hash:sha256' => '[0-9a-f]{64}',
'hash:invalid-algo' => NULL,
- );
+ ];
- $first_set = $this->assertTokens('random', array(), $tokens, array('regex' => TRUE));
- $second_set = $this->assertTokens('random', array(), $tokens, array('regex' => TRUE));
+ $first_set = $this->assertTokens('random', [], $tokens, ['regex' => TRUE]);
+ $second_set = $this->assertTokens('random', [], $tokens, ['regex' => TRUE]);
foreach ($first_set as $token => $value) {
$this->assertNotIdentical($first_set[$token], $second_set[$token]);
}
diff --git a/tests/src/Kernel/TaxonomyTest.php b/tests/src/Kernel/TaxonomyTest.php
index 73274df..783abac 100644
--- a/tests/src/Kernel/TaxonomyTest.php
+++ b/tests/src/Kernel/TaxonomyTest.php
@@ -20,7 +20,7 @@ class TaxonomyTest extends KernelTestBase {
*
* @var array
*/
- public static $modules = array('taxonomy', 'text', 'language');
+ public static $modules = ['taxonomy', 'text', 'language'];
/**
* {@inheritdoc}
@@ -43,31 +43,31 @@ class TaxonomyTest extends KernelTestBase {
* Test the additional taxonomy term tokens.
*/
function testTaxonomyTokens() {
- $root_term = $this->addTerm($this->vocab, array('name' => 'Root term', 'path' => array('alias' => '/root-term')));
- $tokens = array(
- 'url' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $root_term->id()], array('absolute' => TRUE))->toString(),
- 'url:absolute' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $root_term->id()], array('absolute' => TRUE))->toString(),
- 'url:relative' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $root_term->id()], array('absolute' => FALSE))->toString(),
+ $root_term = $this->addTerm($this->vocab, ['name' => 'Root term', 'path' => ['alias' => '/root-term']]);
+ $tokens = [
+ 'url' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $root_term->id()], ['absolute' => TRUE])->toString(),
+ 'url:absolute' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $root_term->id()], ['absolute' => TRUE])->toString(),
+ 'url:relative' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $root_term->id()], ['absolute' => FALSE])->toString(),
'url:path' => '/root-term',
'url:unaliased:path' => "/taxonomy/term/{$root_term->id()}",
- 'edit-url' => Url::fromRoute('entity.taxonomy_term.edit_form', ['taxonomy_term' => $root_term->id()], array('absolute' => TRUE))->toString(),
+ 'edit-url' => Url::fromRoute('entity.taxonomy_term.edit_form', ['taxonomy_term' => $root_term->id()], ['absolute' => TRUE])->toString(),
'parents' => NULL,
'parents:count' => NULL,
'parents:keys' => NULL,
'root' => NULL,
// Deprecated tokens
'url:alias' => '/root-term',
- );
- $this->assertTokens('term', array('term' => $root_term), $tokens);
-
- $parent_term = $this->addTerm($this->vocab, array('name' => 'Parent term', 'parent' => $root_term->id()));
- $tokens = array(
- 'url' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $parent_term->id()], array('absolute' => TRUE))->toString(),
- 'url:absolute' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $parent_term->id()], array('absolute' => TRUE))->toString(),
- 'url:relative' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $parent_term->id()], array('absolute' => FALSE))->toString(),
+ ];
+ $this->assertTokens('term', ['term' => $root_term], $tokens);
+
+ $parent_term = $this->addTerm($this->vocab, ['name' => 'Parent term', 'parent' => $root_term->id()]);
+ $tokens = [
+ 'url' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $parent_term->id()], ['absolute' => TRUE])->toString(),
+ 'url:absolute' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $parent_term->id()], ['absolute' => TRUE])->toString(),
+ 'url:relative' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $parent_term->id()], ['absolute' => FALSE])->toString(),
'url:path' => "/taxonomy/term/{$parent_term->id()}",
'url:unaliased:path' => "/taxonomy/term/{$parent_term->id()}",
- 'edit-url' => Url::fromRoute('entity.taxonomy_term.edit_form', ['taxonomy_term' => $parent_term->id()], array('absolute' => TRUE))->toString(),
+ 'edit-url' => Url::fromRoute('entity.taxonomy_term.edit_form', ['taxonomy_term' => $parent_term->id()], ['absolute' => TRUE])->toString(),
'parents' => 'Root term',
'parents:count' => 1,
'parents:keys' => $root_term->id(),
@@ -75,16 +75,16 @@ class TaxonomyTest extends KernelTestBase {
'root:tid' => $root_term->id(),
// Deprecated tokens
'url:alias' => "/taxonomy/term/{$parent_term->id()}",
- );
- $this->assertTokens('term', array('term' => $parent_term), $tokens);
+ ];
+ $this->assertTokens('term', ['term' => $parent_term], $tokens);
- $term = $this->addTerm($this->vocab, array('name' => 'Test term', 'parent' => $parent_term->id()));
- $tokens = array(
+ $term = $this->addTerm($this->vocab, ['name' => 'Test term', 'parent' => $parent_term->id()]);
+ $tokens = [
'parents' => 'Root term, Parent term',
'parents:count' => 2,
- 'parents:keys' => implode(', ', array($root_term->id(), $parent_term->id())),
- );
- $this->assertTokens('term', array('term' => $term), $tokens);
+ 'parents:keys' => implode(', ', [$root_term->id(), $parent_term->id()]),
+ ];
+ $this->assertTokens('term', ['term' => $term], $tokens);
}
/**
@@ -92,27 +92,27 @@ class TaxonomyTest extends KernelTestBase {
*/
function testVocabularyTokens() {
$vocabulary = $this->vocab;
- $tokens = array(
+ $tokens = [
'machine-name' => 'tags',
- 'edit-url' => Url::fromRoute('entity.taxonomy_vocabulary.edit_form', ['taxonomy_vocabulary' => $vocabulary->id()], array('absolute' => TRUE))->toString(),
- );
- $this->assertTokens('vocabulary', array('vocabulary' => $vocabulary), $tokens);
+ 'edit-url' => Url::fromRoute('entity.taxonomy_vocabulary.edit_form', ['taxonomy_vocabulary' => $vocabulary->id()], ['absolute' => TRUE])->toString(),
+ ];
+ $this->assertTokens('vocabulary', ['vocabulary' => $vocabulary], $tokens);
}
- function addVocabulary(array $vocabulary = array()) {
- $vocabulary += array(
+ function addVocabulary(array $vocabulary = []) {
+ $vocabulary += [
'name' => Unicode::strtolower($this->randomMachineName(5)),
- 'nodes' => array('article' => 'article'),
- );
+ 'nodes' => ['article' => 'article'],
+ ];
$vocabulary = entity_create('taxonomy_vocabulary', $vocabulary)->save();
return $vocabulary;
}
- function addTerm($vocabulary, array $term = array()) {
- $term += array(
+ function addTerm($vocabulary, array $term = []) {
+ $term += [
'name' => Unicode::strtolower($this->randomMachineName(5)),
'vid' => $vocabulary->id(),
- );
+ ];
$term = entity_create('taxonomy_term', $term);
$term->save();
return $term;
@@ -146,6 +146,6 @@ class TaxonomyTest extends KernelTestBase {
])->save();
// Expect the parent term to be in the specified language.
- $this->assertTokens('term', array('term' => $child_term), ['parents' => 'german-parent-term'], ['langcode' => 'de']);
+ $this->assertTokens('term', ['term' => $child_term], ['parents' => 'german-parent-term'], ['langcode' => 'de']);
}
}
diff --git a/tests/src/Kernel/UnitTest.php b/tests/src/Kernel/UnitTest.php
index c91f194..31e60f7 100644
--- a/tests/src/Kernel/UnitTest.php
+++ b/tests/src/Kernel/UnitTest.php
@@ -33,9 +33,9 @@ class UnitTest extends KernelTestBase {
* Test invalid tokens.
*/
public function testGetInvalidTokens() {
- $tests = array();
- $tests[] = array(
- 'valid tokens' => array(
+ $tests = [];
+ $tests[] = [
+ 'valid tokens' => [
'[node:title]',
'[node:created:short]',
'[node:created:custom:invalid]',
@@ -46,8 +46,8 @@ class UnitTest extends KernelTestBase {
'[current-date:short]',
'[current-user:uid]',
'[current-user:ip-address]',
- ),
- 'invalid tokens' => array(
+ ],
+ 'invalid tokens' => [
'[node:title:invalid]',
'[node:created:invalid]',
'[node:created:short:invalid]',
@@ -62,11 +62,11 @@ class UnitTest extends KernelTestBase {
'[node:type]',
'[node:type-name]',
'[date:short]',
- ),
- 'types' => array('node'),
- );
- $tests[] = array(
- 'valid tokens' => array(
+ ],
+ 'types' => ['node'],
+ ];
+ $tests[] = [
+ 'valid tokens' => [
'[node:title]',
'[node:created:short]',
'[node:created:custom:invalid]',
@@ -77,8 +77,8 @@ class UnitTest extends KernelTestBase {
'[user:uid]',
'[current-date:short]',
'[current-user:uid]',
- ),
- 'invalid tokens' => array(
+ ],
+ 'invalid tokens' => [
'[node:title:invalid]',
'[node:created:invalid]',
'[node:created:short:invalid]',
@@ -91,9 +91,9 @@ class UnitTest extends KernelTestBase {
'[node:tnid]',
'[node:type]',
'[node:type-name]',
- ),
- 'types' => array('all'),
- );
+ ],
+ 'types' => ['all'],
+ ];
foreach ($tests as $test) {
$tokens = array_merge($test['valid tokens'], $test['invalid tokens']);
diff --git a/token.install b/token.install
index 664b1af..f143c3a 100644
--- a/token.install
+++ b/token.install
@@ -9,7 +9,7 @@
* Implements hook_requirements().
*/
function token_requirements($phase = 'runtime') {
- $requirements = array();
+ $requirements = [];
if ($phase == 'runtime') {
// Check for various token definition problems.
@@ -24,11 +24,11 @@ function token_requirements($phase = 'runtime') {
'#items' => $problems,
];
- $requirements['token-' . $problem_key] = array(
+ $requirements['token-' . $problem_key] = [
'title' => $problem['label'],
'value' => \Drupal::service('renderer')->renderPlain($build),
'severity' => $problem['severity'],
- );
+ ];
}
}
}
@@ -51,12 +51,12 @@ function token_install() {
$storage = \Drupal::entityTypeManager()->getStorage('entity_view_mode');
// Add a token view mode if it does not already exist.
if (!$storage->load("$entity_type.token")) {
- $storage->create(array(
+ $storage->create([
'targetEntityType' => $entity_type,
'id' => "$entity_type.token",
'status' => TRUE,
'label' => t('Token'),
- ))->save();
+ ])->save();
}
}
}
@@ -65,7 +65,7 @@ function token_install() {
* Build a list of Drupal 6 tokens and their Drupal 7 token names.
*/
function _token_upgrade_token_list() {
- $tokens = array(
+ $tokens = [
// Global tokens
'user-name' => 'current-user:name',
'user-id' => 'current-user:id',
@@ -142,7 +142,7 @@ function _token_upgrade_token_list() {
//'date-in-tz' => '',
'account-url' => 'user:url',
'account-edit' => 'user:edit-url',
- );
+ ];
// Account for date tokens which need to be expanded.
$tokens += _token_upgrade_token_date_list('site-', 'site:date');
@@ -160,8 +160,8 @@ function _token_upgrade_token_list() {
* Build a list of Drupal 6 date tokens and their Drupal 7 token names.
*/
function _token_upgrade_token_date_list($old_token, $new_token) {
- $tokens = array();
- $formats = array(
+ $tokens = [];
+ $formats = [
'yyyy' => 'Y',
'yy' => 'y',
'month' => 'F',
@@ -174,7 +174,7 @@ function _token_upgrade_token_date_list($old_token, $new_token) {
'ddd' => 'D',
'dd' => 'd',
'd' => 'j',
- );
+ ];
foreach ($formats as $token_format => $date_format) {
$tokens[$old_token . $token_format] = "$new_token:custom:$date_format";
}
@@ -198,7 +198,7 @@ function _token_upgrade_token_date_list($old_token, $new_token) {
*
* @see _token_upgrade_token_list()
*/
-function token_update_token_text($text, $updates = array(), $leading = '[', $trailing = ']') {
+function token_update_token_text($text, $updates = [], $leading = '[', $trailing = ']') {
$updates += _token_upgrade_token_list();
$regex = '/' . preg_quote($leading, '/') . '([^\s]*)' . preg_quote($trailing, '/') . '/';
preg_match_all($regex, $text, $matches);
@@ -246,28 +246,28 @@ function token_get_token_problems() {
//}
$token_info = \Drupal::token()->getInfo();
- $token_problems = array(
- 'not-array' => array(
+ $token_problems = [
+ 'not-array' => [
'label' => t('Tokens or token types not defined as arrays'),
'severity' => REQUIREMENT_ERROR,
- ),
- 'missing-info' => array(
+ ],
+ 'missing-info' => [
'label' => t('Tokens or token types missing name property'),
'severity' => REQUIREMENT_WARNING,
- ),
- 'type-no-tokens' => array(
+ ],
+ 'type-no-tokens' => [
'label' => t('Token types do not have any tokens defined'),
'severity' => REQUIREMENT_INFO,
- ),
- 'tokens-no-type' => array(
+ ],
+ 'tokens-no-type' => [
'label' => t('Token types are not defined but have tokens'),
'severity' => REQUIREMENT_INFO,
- ),
- 'duplicate' => array(
+ ],
+ 'duplicate' => [
'label' => t('Token or token types are defined by multiple modules'),
'severity' => REQUIREMENT_ERROR,
- ),
- );
+ ],
+ ];
// Check token types for problems.
foreach ($token_info['types'] as $type => $type_info) {
diff --git a/token.module b/token.module
index 32a38da..d210777 100644
--- a/token.module
+++ b/token.module
@@ -47,7 +47,7 @@ function token_help($route_name, RouteMatchInterface $route_match) {
* Return an array of the core modules supported by token.module.
*/
function _token_core_supported_modules() {
- return array('book', 'field', 'menu_ui');
+ return ['book', 'field', 'menu_ui'];
}
/**
@@ -106,7 +106,7 @@ function token_form_block_form_alter(&$form, FormStateInterface $form_state) {
* Implements hook_field_info_alter().
*/
function token_field_info_alter(&$info) {
- $defaults = array(
+ $defaults = [
'taxonomy_term_reference' => 'taxonomy_term_reference_plain',
'number_integer' => 'number_unformatted',
'number_decimal' => 'number_unformatted',
@@ -120,10 +120,10 @@ function token_field_info_alter(&$info) {
'list_float' => 'list_default',
'list_string' => 'list_default',
'list_boolean' => 'list_default',
- );
+ ];
foreach ($defaults as $field_type => $default_token_formatter) {
if (isset($info[$field_type])) {
- $info[$field_type] += array('default_token_formatter' => $default_token_formatter);
+ $info[$field_type] += ['default_token_formatter' => $default_token_formatter];
}
}
}
@@ -226,7 +226,7 @@ function token_module_implements_alter(&$implementations, $hook) {
// other modules.
if (isset($implementations['token'])) {
unset($implementations['token']);
- $implementations = array_merge(array('token' => 'tokens'), $implementations);
+ $implementations = array_merge(['token' => 'tokens'], $implementations);
}
}
}
@@ -281,13 +281,13 @@ function token_element_validate($element, FormStateInterface $form_state) {
// Validate if an element must have a minimum number of tokens.
if (isset($element['#min_tokens']) && count($tokens) < $element['#min_tokens']) {
- $error = \Drupal::translation()->formatPlural($element['#min_tokens'], '%name must contain at least one token.', '%name must contain at least @count tokens.', array('%name' => $title));
+ $error = \Drupal::translation()->formatPlural($element['#min_tokens'], '%name must contain at least one token.', '%name must contain at least @count tokens.', ['%name' => $title]);
$form_state->setError($element, $error);
}
// Validate if an element must have a maximum number of tokens.
if (isset($element['#max_tokens']) && count($tokens) > $element['#max_tokens']) {
- $error = \Drupal::translation()->formatPlural($element['#max_tokens'], '%name must contain at most one token.', '%name must contain at most @count tokens.', array('%name' => $title));
+ $error = \Drupal::translation()->formatPlural($element['#max_tokens'], '%name must contain at most one token.', '%name must contain at most @count tokens.', ['%name' => $title]);
$form_state->setError($element, $error);
}
@@ -295,7 +295,7 @@ function token_element_validate($element, FormStateInterface $form_state) {
if (isset($element['#token_types'])) {
$invalid_tokens = \Drupal::token()->getInvalidTokensByContext($tokens, $element['#token_types']);
if ($invalid_tokens) {
- $form_state->setError($element, t('%name is using the following invalid tokens: @invalid-tokens.', array('%name' => $title, '@invalid-tokens' => implode(', ', $invalid_tokens))));
+ $form_state->setError($element, t('%name is using the following invalid tokens: @invalid-tokens.', ['%name' => $title, '@invalid-tokens' => implode(', ', $invalid_tokens)]));
}
}
@@ -318,19 +318,19 @@ function token_form_field_config_edit_form_alter(&$form, FormStateInterface $for
// Date support needs to be implicitly added, as while technically it's not
// a global token, it is a not only used but is the default value.
// https://www.drupal.org/node/2642160
- $form['settings']['file_directory'] += array('#token_types' => array('date'));
+ $form['settings']['file_directory'] += ['#token_types' => ['date']];
$form['settings']['file_directory']['#description'] .= ' ' . t('This field supports tokens.');
}
// Note that the description is tokenized via token_field_widget_form_alter().
$form['description']['#element_validate'][] = 'token_element_validate';
- $form['description'] += array('#token_types' => array());
+ $form['description'] += ['#token_types' => []];
- $form['token_tree'] = array(
+ $form['token_tree'] = [
'#theme' => 'token_tree_link',
- '#token_types' => array(),
+ '#token_types' => [],
'#weight' => $form['description']['#weight'] + 0.5,
- );
+ ];
}
/**
@@ -398,24 +398,24 @@ function token_form_user_admin_settings_alter(&$form, FormStateInterface $form_s
elseif ($element[$sub_key]['#type'] == 'textfield' && substr($sub_key, -8) === '_subject') {
// Add validation to subject textfields.
$element[$sub_key]['#element_validate'][] = 'token_element_validate';
- $element[$sub_key] += array('#token_types' => array('user'));
+ $element[$sub_key] += ['#token_types' => ['user']];
}
elseif ($element[$sub_key]['#type'] == 'textarea' && substr($sub_key, -5) === '_body') {
// Add validation to body textareas.
$element[$sub_key]['#element_validate'][] = 'token_element_validate';
- $element[$sub_key] += array('#token_types' => array('user'));
+ $element[$sub_key] += ['#token_types' => ['user']];
}
}
}
// Add the token tree UI.
- $form['email']['token_tree'] = array(
+ $form['email']['token_tree'] = [
'#theme' => 'token_tree_link',
- '#token_types' => array('user'),
+ '#token_types' => ['user'],
'#show_restricted' => TRUE,
'#show_nested' => FALSE,
'#weight' => 90,
- );
+ ];
}
/**
@@ -427,10 +427,10 @@ function token_form_user_admin_settings_alter(&$form, FormStateInterface $form_s
* The cleaned token name.
*/
function token_clean_token_name($name) {
- static $names = array();
+ static $names = [];
if (!isset($names[$name])) {
- $cleaned_name = strtr($name, array(' ' => '-', '_' => '-', '/' => '-', '[' => '-', ']' => ''));
+ $cleaned_name = strtr($name, [' ' => '-', '_' => '-', '/' => '-', '[' => '-', ']' => '']);
$cleaned_name = preg_replace('/[^\w\-]/i', '', $cleaned_name);
$cleaned_name = trim($cleaned_name, '-');
$names[$name] = $cleaned_name;
@@ -442,8 +442,8 @@ function token_clean_token_name($name) {
/**
* Do not use this function yet. Its API has not been finalized.
*/
-function token_render_array(array $array, array $options = array()) {
- $rendered = array();
+function token_render_array(array $array, array $options = []) {
+ $rendered = [];
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = \Drupal::service('renderer');
@@ -459,7 +459,7 @@ function token_render_array(array $array, array $options = array()) {
/**
* Do not use this function yet. Its API has not been finalized.
*/
-function token_render_array_value($value, array $options = array()) {
+function token_render_array_value($value, array $options = []) {
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = \Drupal::service('renderer');
@@ -493,7 +493,7 @@ function token_render_cache_get($elements) {
*/
function token_render_cache_set(&$markup, $elements) {
// This should only run of drupal_render_cache_set() did not.
- if (in_array(\Drupal::request()->server->get('REQUEST_METHOD'), array('GET', 'HEAD'))) {
+ if (in_array(\Drupal::request()->server->get('REQUEST_METHOD'), ['GET', 'HEAD'])) {
return FALSE;
}
@@ -515,10 +515,10 @@ function token_render_cache_set(&$markup, $elements) {
* List of menu link parent titles.
*/
function token_menu_link_load_all_parents($plugin_id, $langcode) {
- $cache = &drupal_static(__FUNCTION__, array());
+ $cache = &drupal_static(__FUNCTION__, []);
if (!isset($cache[$plugin_id][$langcode])) {
- $cache[$plugin_id][$langcode] = array();
+ $cache[$plugin_id][$langcode] = [];
/** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
$menu_link_manager = \Drupal::service('plugin.manager.menu.link');
$parent_ids = $menu_link_manager->getParentIds($plugin_id);
@@ -526,7 +526,7 @@ function token_menu_link_load_all_parents($plugin_id, $langcode) {
unset($parent_ids[$plugin_id]);
foreach ($parent_ids as $parent_id) {
$parent = $menu_link_manager->createInstance($parent_id);
- $cache[$plugin_id][$langcode] = array($parent_id => token_menu_link_translated_title($parent, $langcode)) + $cache[$plugin_id][$langcode];
+ $cache[$plugin_id][$langcode] = [$parent_id => token_menu_link_translated_title($parent, $langcode)] + $cache[$plugin_id][$langcode];
}
}
@@ -573,14 +573,14 @@ function token_menu_link_translated_title(MenuLinkInterface $menu_link, $langcod
* The term parents collection.
*/
function token_taxonomy_term_load_all_parents($tid, $langcode) {
- $cache = &drupal_static(__FUNCTION__, array());
+ $cache = &drupal_static(__FUNCTION__, []);
if (!is_numeric($tid)) {
- return array();
+ return [];
}
if (!isset($cache[$langcode][$tid])) {
- $cache[$langcode][$tid] = array();
+ $cache[$langcode][$tid] = [];
/** @var \Drupal\taxonomy\TermStorageInterface $term_storage */
$term_storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term');
$parents = $term_storage->loadAllParents($tid);
@@ -601,7 +601,7 @@ function token_element_children(&$elements, $sort = FALSE) {
$sort = isset($elements['#sorted']) ? !$elements['#sorted'] : $sort;
// Filter out properties from the element, leaving only children.
- $children = array();
+ $children = [];
$sortable = FALSE;
foreach ($elements as $key => $value) {
if ($key === '' || $key[0] !== '#') {
@@ -639,15 +639,15 @@ function token_element_children(&$elements, $sort = FALSE) {
* List of node titles of the book parents.
*/
function token_book_load_all_parents(array $book) {
- $cache = &drupal_static(__FUNCTION__, array());
+ $cache = &drupal_static(__FUNCTION__, []);
if (empty($book['nid'])) {
- return array();
+ return [];
}
$nid = $book['nid'];
if (!isset($cache[$nid])) {
- $cache[$nid] = array();
+ $cache[$nid] = [];
$i = 1;
while ($book["p$i"] != $nid) {
$cache[$nid][] = Node::load($book["p$i"])->getTitle();
@@ -673,14 +673,14 @@ function token_entity_base_field_info(EntityTypeInterface $entity_type) {
->setRevisionable(TRUE)
->setSetting('target_type', 'menu_link_content')
->setTranslatable(TRUE)
- ->setDisplayOptions('view', array(
+ ->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'hidden',
- ))
+ ])
->setComputed(TRUE)
- ->setDisplayOptions('form', array(
+ ->setDisplayOptions('form', [
'type' => 'hidden',
- ));
+ ]);
return $fields;
}
@@ -740,19 +740,19 @@ function token_node_menu_link_submit($entity_type, NodeInterface $node, &$form,
else {
if ($node->isNew()) {
// Create a new menu_link_content entity.
- $entity = MenuLinkContent::create(array(
+ $entity = MenuLinkContent::create([
// Lets just reference the UUID for now, the link is not important for
// token generation.
'link' => ['uri' => 'internal:/node/' . $node->uuid()],
'langcode' => $node->language()->getId(),
- ));
+ ]);
}
else {
// Create a new menu_link_content entity.
- $entity = MenuLinkContent::create(array(
+ $entity = MenuLinkContent::create([
'link' => ['uri' => 'entity:node/' . $node->id()],
'langcode' => $node->language()->getId(),
- ));
+ ]);
}
}
$entity->title->value = trim($values['title']);
diff --git a/token.tokens.inc b/token.tokens.inc
index f6ad619..5f67132 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -33,11 +33,11 @@ function token_token_info_alter(&$info) {
// Force 'date' type tokens to require input and add a 'current-date' type.
// @todo Remove when http://drupal.org/node/943028 is fixed.
$info['types']['date']['needs-data'] = 'date';
- $info['types']['current-date'] = array(
+ $info['types']['current-date'] = [
'name' => t('Current date'),
'description' => t('Tokens related to the current date and time.'),
'type' => 'date',
- );
+ ];
// Add a 'dynamic' key to any tokens that have chained but dynamic tokens.
$info['tokens']['date']['custom']['dynamic'] = TRUE;
@@ -87,22 +87,22 @@ function token_token_info_alter(&$info) {
// Add [entity:url] tokens if they do not already exist.
// @todo Support entity:label
if (!isset($info['tokens'][$token_type]['url'])) {
- $info['tokens'][$token_type]['url'] = array(
+ $info['tokens'][$token_type]['url'] = [
'name' => t('URL'),
- 'description' => t('The URL of the @entity.', array('@entity' => Unicode::strtolower($entity_info->getLabel()))),
+ 'description' => t('The URL of the @entity.', ['@entity' => Unicode::strtolower($entity_info->getLabel())]),
'module' => 'token',
'type' => 'url',
- );
+ ];
}
// Add [entity:original] tokens if they do not already exist.
if (!isset($info['tokens'][$token_type]['original'])) {
- $info['tokens'][$token_type]['original'] = array(
- 'name' => t('Original @entity', array('@entity' => Unicode::strtolower($entity_info->getLabel()))),
- 'description' => t('The original @entity data if the @entity is being updated or saved.', array('@entity' => Unicode::strtolower($entity_info->getLabel()))),
+ $info['tokens'][$token_type]['original'] = [
+ 'name' => t('Original @entity', ['@entity' => Unicode::strtolower($entity_info->getLabel())]),
+ 'description' => t('The original @entity data if the @entity is being updated or saved.', ['@entity' => Unicode::strtolower($entity_info->getLabel())]),
'module' => 'token',
'type' => $token_type,
- );
+ ];
}
}
@@ -112,11 +112,11 @@ function token_token_info_alter(&$info) {
foreach ($date_format_types as $date_format_type => $date_format_type_info) {
/* @var \Drupal\system\Entity\DateFormat $date_format_type_info */
if (!isset($info['tokens']['date'][$date_format_type])) {
- $info['tokens']['date'][$date_format_type] = array(
+ $info['tokens']['date'][$date_format_type] = [
'name' => Html::escape($date_format_type_info->label()),
- 'description' => t("A date in '@type' format. (%date)", array('@type' => $date_format_type, '%date' => format_date(REQUEST_TIME, $date_format_type))),
+ 'description' => t("A date in '@type' format. (%date)", ['@type' => $date_format_type, '%date' => format_date(REQUEST_TIME, $date_format_type)]),
'module' => 'token',
- );
+ ];
}
}
}
@@ -126,264 +126,264 @@ function token_token_info_alter(&$info) {
*/
function token_token_info() {
// Node tokens.
- $info['tokens']['node']['source'] = array(
+ $info['tokens']['node']['source'] = [
'name' => t('Translation source node'),
'description' => t("The source node for this current node's translation set."),
'type' => 'node',
- );
- $info['tokens']['node']['log'] = array(
+ ];
+ $info['tokens']['node']['log'] = [
'name' => t('Revision log message'),
'description' => t('The explanation of the most recent changes made to the node.'),
- );
- $info['tokens']['node']['content-type'] = array(
+ ];
+ $info['tokens']['node']['content-type'] = [
'name' => t('Content type'),
'description' => t('The content type of the node.'),
'type' => 'content-type',
- );
+ ];
// Content type tokens.
- $info['types']['content-type'] = array(
+ $info['types']['content-type'] = [
'name' => t('Content types'),
'description' => t('Tokens related to content types.'),
'needs-data' => 'node_type',
- );
- $info['tokens']['content-type']['name'] = array(
+ ];
+ $info['tokens']['content-type']['name'] = [
'name' => t('Name'),
'description' => t('The name of the content type.'),
- );
- $info['tokens']['content-type']['machine-name'] = array(
+ ];
+ $info['tokens']['content-type']['machine-name'] = [
'name' => t('Machine-readable name'),
'description' => t('The unique machine-readable name of the content type.'),
- );
- $info['tokens']['content-type']['description'] = array(
+ ];
+ $info['tokens']['content-type']['description'] = [
'name' => t('Description'),
'description' => t('The optional description of the content type.'),
- );
- $info['tokens']['content-type']['node-count'] = array(
+ ];
+ $info['tokens']['content-type']['node-count'] = [
'name' => t('Node count'),
'description' => t('The number of nodes belonging to the content type.'),
- );
- $info['tokens']['content-type']['edit-url'] = array(
+ ];
+ $info['tokens']['content-type']['edit-url'] = [
'name' => t('Edit URL'),
'description' => t("The URL of the content type's edit page."),
// 'type' => 'url',
- );
+ ];
// Taxonomy term and vocabulary tokens.
if (\Drupal::moduleHandler()->moduleExists('taxonomy')) {
- $info['tokens']['term']['edit-url'] = array(
+ $info['tokens']['term']['edit-url'] = [
'name' => t('Edit URL'),
'description' => t("The URL of the taxonomy term's edit page."),
// 'type' => 'url',
- );
- $info['tokens']['term']['parents'] = array(
+ ];
+ $info['tokens']['term']['parents'] = [
'name' => t('Parents'),
'description' => t("An array of all the term's parents, starting with the root."),
'type' => 'array',
- );
- $info['tokens']['term']['root'] = array(
+ ];
+ $info['tokens']['term']['root'] = [
'name' => t('Root term'),
'description' => t("The root term of the taxonomy term."),
'type' => 'term',
- );
+ ];
- $info['tokens']['vocabulary']['machine-name'] = array(
+ $info['tokens']['vocabulary']['machine-name'] = [
'name' => t('Machine-readable name'),
'description' => t('The unique machine-readable name of the vocabulary.'),
- );
- $info['tokens']['vocabulary']['edit-url'] = array(
+ ];
+ $info['tokens']['vocabulary']['edit-url'] = [
'name' => t('Edit URL'),
'description' => t("The URL of the vocabulary's edit page."),
// 'type' => 'url',
- );
+ ];
}
// File tokens.
- $info['tokens']['file']['basename'] = array(
+ $info['tokens']['file']['basename'] = [
'name' => t('Base name'),
'description' => t('The base name of the file.'),
- );
- $info['tokens']['file']['extension'] = array(
+ ];
+ $info['tokens']['file']['extension'] = [
'name' => t('Extension'),
'description' => t('The extension of the file.'),
- );
- $info['tokens']['file']['size-raw'] = array(
+ ];
+ $info['tokens']['file']['size-raw'] = [
'name' => t('File byte size'),
'description' => t('The size of the file, in bytes.'),
- );
+ ];
// User tokens.
// Add information on the restricted user tokens.
- $info['tokens']['user']['cancel-url'] = array(
+ $info['tokens']['user']['cancel-url'] = [
'name' => t('Account cancellation URL'),
'description' => t('The URL of the confirm delete page for the user account.'),
'restricted' => TRUE,
// 'type' => 'url',
- );
- $info['tokens']['user']['one-time-login-url'] = array(
+ ];
+ $info['tokens']['user']['one-time-login-url'] = [
'name' => t('One-time login URL'),
'description' => t('The URL of the one-time login page for the user account.'),
'restricted' => TRUE,
// 'type' => 'url',
- );
- $info['tokens']['user']['roles'] = array(
+ ];
+ $info['tokens']['user']['roles'] = [
'name' => t('Roles'),
'description' => t('The user roles associated with the user account.'),
'type' => 'array',
- );
+ ];
// Current user tokens.
- $info['tokens']['current-user']['ip-address'] = array(
+ $info['tokens']['current-user']['ip-address'] = [
'name' => t('IP address'),
'description' => 'The IP address of the current user.',
- );
+ ];
// Menu link tokens (work regardless if menu module is enabled or not).
- $info['types']['menu-link'] = array(
+ $info['types']['menu-link'] = [
'name' => t('Menu links'),
'description' => t('Tokens related to menu links.'),
'needs-data' => 'menu-link',
- );
- $info['tokens']['menu-link']['mlid'] = array(
+ ];
+ $info['tokens']['menu-link']['mlid'] = [
'name' => t('Link ID'),
'description' => t('The unique ID of the menu link.'),
- );
- $info['tokens']['menu-link']['title'] = array(
+ ];
+ $info['tokens']['menu-link']['title'] = [
'name' => t('Title'),
'description' => t('The title of the menu link.'),
- );
- $info['tokens']['menu-link']['url'] = array(
+ ];
+ $info['tokens']['menu-link']['url'] = [
'name' => t('URL'),
'description' => t('The URL of the menu link.'),
'type' => 'url',
- );
- $info['tokens']['menu-link']['parent'] = array(
+ ];
+ $info['tokens']['menu-link']['parent'] = [
'name' => t('Parent'),
'description' => t("The menu link's parent."),
'type' => 'menu-link',
- );
- $info['tokens']['menu-link']['parents'] = array(
+ ];
+ $info['tokens']['menu-link']['parents'] = [
'name' => t('Parents'),
'description' => t("An array of all the menu link's parents, starting with the root."),
'type' => 'array',
- );
- $info['tokens']['menu-link']['root'] = array(
+ ];
+ $info['tokens']['menu-link']['root'] = [
'name' => t('Root'),
'description' => t("The menu link's root."),
'type' => 'menu-link',
- );
+ ];
// Current page tokens.
- $info['types']['current-page'] = array(
+ $info['types']['current-page'] = [
'name' => t('Current page'),
'description' => t('Tokens related to the current page request.'),
- );
- $info['tokens']['current-page']['title'] = array(
+ ];
+ $info['tokens']['current-page']['title'] = [
'name' => t('Title'),
'description' => t('The title of the current page.'),
- );
- $info['tokens']['current-page']['url'] = array(
+ ];
+ $info['tokens']['current-page']['url'] = [
'name' => t('URL'),
'description' => t('The URL of the current page.'),
'type' => 'url',
- );
- $info['tokens']['current-page']['page-number'] = array(
+ ];
+ $info['tokens']['current-page']['page-number'] = [
'name' => t('Page number'),
'description' => t('The page number of the current page when viewing paged lists.'),
- );
- $info['tokens']['current-page']['query'] = array(
+ ];
+ $info['tokens']['current-page']['query'] = [
'name' => t('Query string value'),
'description' => t('The value of a specific query string field of the current page.'),
'dynamic' => TRUE,
- );
+ ];
// URL tokens.
- $info['types']['url'] = array(
+ $info['types']['url'] = [
'name' => t('URL'),
'description' => t('Tokens related to URLs.'),
'needs-data' => 'path',
- );
- $info['tokens']['url']['path'] = array(
+ ];
+ $info['tokens']['url']['path'] = [
'name' => t('Path'),
'description' => t('The path component of the URL.'),
- );
- $info['tokens']['url']['relative'] = array(
+ ];
+ $info['tokens']['url']['relative'] = [
'name' => t('Relative URL'),
'description' => t('The relative URL.'),
- );
- $info['tokens']['url']['absolute'] = array(
+ ];
+ $info['tokens']['url']['absolute'] = [
'name' => t('Absolute URL'),
'description' => t('The absolute URL.'),
- );
- $info['tokens']['url']['brief'] = array(
+ ];
+ $info['tokens']['url']['brief'] = [
'name' => t('Brief URL'),
'description' => t('The URL without the protocol and trailing backslash.'),
- );
- $info['tokens']['url']['unaliased'] = array(
+ ];
+ $info['tokens']['url']['unaliased'] = [
'name' => t('Unaliased URL'),
'description' => t('The unaliased URL.'),
'type' => 'url',
- );
- $info['tokens']['url']['args'] = array(
+ ];
+ $info['tokens']['url']['args'] = [
'name' => t('Arguments'),
'description' => t("The specific argument of the current page (e.g. 'arg:1' on the page 'node/1' returns '1')."),
'type' => 'array',
- );
+ ];
// Array tokens.
- $info['types']['array'] = array(
+ $info['types']['array'] = [
'name' => t('Array'),
'description' => t('Tokens related to arrays of strings.'),
'needs-data' => 'array',
'nested' => TRUE,
- );
- $info['tokens']['array']['first'] = array(
+ ];
+ $info['tokens']['array']['first'] = [
'name' => t('First'),
'description' => t('The first element of the array.'),
- );
- $info['tokens']['array']['last'] = array(
+ ];
+ $info['tokens']['array']['last'] = [
'name' => t('Last'),
'description' => t('The last element of the array.'),
- );
- $info['tokens']['array']['count'] = array(
+ ];
+ $info['tokens']['array']['count'] = [
'name' => t('Count'),
'description' => t('The number of elements in the array.'),
- );
- $info['tokens']['array']['reversed'] = array(
+ ];
+ $info['tokens']['array']['reversed'] = [
'name' => t('Reversed'),
'description' => t('The array reversed.'),
'type' => 'array',
- );
- $info['tokens']['array']['keys'] = array(
+ ];
+ $info['tokens']['array']['keys'] = [
'name' => t('Keys'),
'description' => t('The array of keys of the array.'),
'type' => 'array',
- );
- $info['tokens']['array']['join'] = array(
+ ];
+ $info['tokens']['array']['join'] = [
'name' => t('Imploded'),
'description' => t('The values of the array joined together with a custom string in-between each value.'),
'dynamic' => TRUE,
- );
- $info['tokens']['array']['value'] = array(
+ ];
+ $info['tokens']['array']['value'] = [
'name' => t('Value'),
'description' => t('The specific value of the array.'),
'dynamic' => TRUE,
- );
+ ];
// Random tokens.
- $info['types']['random'] = array(
+ $info['types']['random'] = [
'name' => t('Random'),
'description' => t('Tokens related to random data.'),
- );
- $info['tokens']['random']['number'] = array(
+ ];
+ $info['tokens']['random']['number'] = [
'name' => t('Number'),
- 'description' => t('A random number from 0 to @max.', array('@max' => mt_getrandmax())),
- );
- $info['tokens']['random']['hash'] = array(
+ 'description' => t('A random number from 0 to @max.', ['@max' => mt_getrandmax()]),
+ ];
+ $info['tokens']['random']['hash'] = [
'name' => t('Hash'),
- 'description' => t('A random hash. The possible hashing algorithms are: @hash-algos.', array('@hash-algos' => implode(', ', hash_algos()))),
+ 'description' => t('A random hash. The possible hashing algorithms are: @hash-algos.', ['@hash-algos' => implode(', ', hash_algos())]),
'dynamic' => TRUE,
- );
+ ];
// Define image_with_image_style token type.
if (\Drupal::moduleHandler()->moduleExists('image')) {
@@ -427,10 +427,10 @@ function token_token_info() {
/**
* Implements hook_tokens().
*/
-function token_tokens($type, array $tokens, array $data = array(), array $options = array(), BubbleableMetadata $bubbleable_metadata) {
- $replacements = array();
+function token_tokens($type, array $tokens, array $data = [], array $options = [], BubbleableMetadata $bubbleable_metadata) {
+ $replacements = [];
$language_manager = \Drupal::languageManager();
- $url_options = array('absolute' => TRUE);
+ $url_options = ['absolute' => TRUE];
if (isset($options['langcode'])) {
$url_options['language'] = $language_manager->getLanguage($options['langcode']);
$langcode = $options['langcode'];
@@ -455,7 +455,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
// Current date tokens.
// @todo Remove when http://drupal.org/node/943028 is fixed.
if ($type == 'current-date') {
- $replacements += \Drupal::token()->generate('date', $tokens, array('date' => REQUEST_TIME), $options, $bubbleable_metadata);
+ $replacements += \Drupal::token()->generate('date', $tokens, ['date' => REQUEST_TIME], $options, $bubbleable_metadata);
}
// Comment tokens.
@@ -466,7 +466,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
// Chained token relationships.
if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url'))) {
// Add fragment to url options.
- $replacements += \Drupal::token()->generate('url', $url_tokens, array('url' => $comment->urlInfo('canonical', ['fragment' => "comment-{$comment->id()}"])), $options, $bubbleable_metadata);
+ $replacements += \Drupal::token()->generate('url', $url_tokens, ['url' => $comment->urlInfo('canonical', ['fragment' => "comment-{$comment->id()}"])], $options, $bubbleable_metadata);
}
}
@@ -489,13 +489,13 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
// Chained token relationships.
if (($parent_tokens = \Drupal::token()->findWithPrefix($tokens, 'source')) && $source_node = $node->getUntranslated()) {
- $replacements += \Drupal::token()->generate('node', $parent_tokens, array('node' => $source_node), $options, $bubbleable_metadata);
+ $replacements += \Drupal::token()->generate('node', $parent_tokens, ['node' => $source_node], $options, $bubbleable_metadata);
}
if (($node_type_tokens = \Drupal::token()->findWithPrefix($tokens, 'content-type')) && $node_type = node_type_load($node->bundle())) {
- $replacements += \Drupal::token()->generate('content-type', $node_type_tokens, array('node_type' => $node_type), $options, $bubbleable_metadata);
+ $replacements += \Drupal::token()->generate('content-type', $node_type_tokens, ['node_type' => $node_type], $options, $bubbleable_metadata);
}
if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url'))) {
- $replacements += \Drupal::token()->generate('url', $url_tokens, array('url' => $node->urlInfo()), $options, $bubbleable_metadata);
+ $replacements += \Drupal::token()->generate('url', $url_tokens, ['url' => $node->urlInfo()], $options, $bubbleable_metadata);
}
}
@@ -561,19 +561,19 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
// Chained token relationships.
if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url'))) {
- $replacements += \Drupal::token()->generate('url', $url_tokens, array('url' => $term->urlInfo()), $options, $bubbleable_metadata);
+ $replacements += \Drupal::token()->generate('url', $url_tokens, ['url' => $term->urlInfo()], $options, $bubbleable_metadata);
}
// [term:parents:*] chained tokens.
if ($parents_tokens = \Drupal::token()->findWithPrefix($tokens, 'parents')) {
if ($parents = token_taxonomy_term_load_all_parents($term->id(), $langcode)) {
- $replacements += \Drupal::token()->generate('array', $parents_tokens, array('array' => $parents), $options, $bubbleable_metadata);
+ $replacements += \Drupal::token()->generate('array', $parents_tokens, ['array' => $parents], $options, $bubbleable_metadata);
}
}
if ($root_tokens = \Drupal::token()->findWithPrefix($tokens, 'root')) {
$parents = $term_storage->loadAllParents($term->id());
$root_term = end($parents);
if ($root_term->tid != $term->id()) {
- $replacements += \Drupal::token()->generate('term', $root_tokens, array('term' => $root_term), $options, $bubbleable_metadata);
+ $replacements += \Drupal::token()->generate('term', $root_tokens, ['term' => $root_term], $options, $bubbleable_metadata);
}
}
}
@@ -644,15 +644,15 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
// Chained token relationships.
if ($account instanceof UserInterface && $account->hasField('user_picture') && ($picture_tokens = \Drupal::token()->findWithPrefix($tokens, 'picture'))) {
- $replacements += \Drupal::token()->generate('file', $picture_tokens, array('file' => $account->user_picture->entity), $options, $bubbleable_metadata);
+ $replacements += \Drupal::token()->generate('file', $picture_tokens, ['file' => $account->user_picture->entity], $options, $bubbleable_metadata);
}
if ($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url')) {
- $replacements += \Drupal::token()->generate('url', $url_tokens, array('url' => $account->urlInfo()), $options, $bubbleable_metadata);
+ $replacements += \Drupal::token()->generate('url', $url_tokens, ['url' => $account->urlInfo()], $options, $bubbleable_metadata);
}
if ($role_tokens = \Drupal::token()->findWithPrefix($tokens, 'roles')) {
$roles = $account->getRoles();
$roles_names = array_combine($roles, $roles);
- $replacements += \Drupal::token()->generate('array', $role_tokens, array('array' => $roles_names), $options, $bubbleable_metadata);
+ $replacements += \Drupal::token()->generate('array', $role_tokens, ['array' => $roles_names], $options, $bubbleable_metadata);
}
}
@@ -714,20 +714,20 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
// Chained token relationships.
/** @var \Drupal\Core\Menu\MenuLinkInterface $parent */
if ($link->getParent() && ($parent_tokens = \Drupal::token()->findWithPrefix($tokens, 'parent')) && $parent = $menu_link_manager->createInstance($link->getParent())) {
- $replacements += \Drupal::token()->generate('menu-link', $parent_tokens, array('menu-link' => $parent), $options, $bubbleable_metadata);
+ $replacements += \Drupal::token()->generate('menu-link', $parent_tokens, ['menu-link' => $parent], $options, $bubbleable_metadata);
}
// [menu-link:parents:*] chained tokens.
if ($parents_tokens = \Drupal::token()->findWithPrefix($tokens, 'parents')) {
if ($parents = token_menu_link_load_all_parents($link->getPluginId(), $langcode)) {
- $replacements += \Drupal::token()->generate('array', $parents_tokens, array('array' => $parents), $options, $bubbleable_metadata);
+ $replacements += \Drupal::token()->generate('array', $parents_tokens, ['array' => $parents], $options, $bubbleable_metadata);
}
}
if (($root_tokens = \Drupal::token()->findWithPrefix($tokens, 'root')) && $link->getParent() && $parent_ids = array_keys(token_menu_link_load_all_parents($link->getPluginId(), $langcode))) {
$root = $menu_link_manager->createInstance(array_shift($parent_ids));
- $replacements += \Drupal::token()->generate('menu-link', $root_tokens, array('menu-link' => $root), $options, $bubbleable_metadata);
+ $replacements += \Drupal::token()->generate('menu-link', $root_tokens, ['menu-link' => $root], $options, $bubbleable_metadata);
}
if ($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url')) {
- $replacements += \Drupal::token()->generate('url', $url_tokens, array('url' => $link->getUrlObject()), $options, $bubbleable_metadata);
+ $replacements += \Drupal::token()->generate('url', $url_tokens, ['url' => $link->getUrlObject()], $options, $bubbleable_metadata);
}
}
@@ -785,7 +785,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
// Chained token relationships.
if ($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url')) {
$url = Url::fromRoute('');
- $replacements += \Drupal::token()->generate('url', $url_tokens, array('url' => $url), $options, $bubbleable_metadata);
+ $replacements += \Drupal::token()->generate('url', $url_tokens, ['url' => $url], $options, $bubbleable_metadata);
}
}
@@ -815,7 +815,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
$replacements[$original] = $url->setAbsolute(FALSE)->toString();
break;
case 'brief':
- $replacements[$original] = preg_replace(array('!^https?://!', '!/$!'), '', $url->setAbsolute()->toString());
+ $replacements[$original] = preg_replace(['!^https?://!', '!/$!'], '', $url->setAbsolute()->toString());
break;
case 'unaliased':
$unaliased = clone $url;
@@ -832,13 +832,13 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
// [url:args:*] chained tokens.
if ($arg_tokens = \Drupal::token()->findWithPrefix($tokens, 'args')) {
$value = !($url->getOption('alias')) ? \Drupal::service('path.alias_manager')->getAliasByPath($path, $langcode) : $path;
- $replacements += \Drupal::token()->generate('array', $arg_tokens, array('array' => explode('/', ltrim($value, '/'))), $options, $bubbleable_metadata);
+ $replacements += \Drupal::token()->generate('array', $arg_tokens, ['array' => explode('/', ltrim($value, '/'))], $options, $bubbleable_metadata);
}
// [url:unaliased:*] chained tokens.
if ($unaliased_tokens = \Drupal::token()->findWithPrefix($tokens, 'unaliased')) {
$url->setOption('alias', TRUE);
- $replacements += \Drupal::token()->generate('url', $unaliased_tokens, array('url' => $url), $options, $bubbleable_metadata);
+ $replacements += \Drupal::token()->generate('url', $unaliased_tokens, ['url' => $url], $options, $bubbleable_metadata);
}
}
@@ -866,20 +866,20 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
// [entity:url:*] chained tokens.
if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url')) && _token_module($type, 'url') == 'token') {
- $replacements += \Drupal::token()->generate('url', $url_tokens, array('url' => $entity->toUrl()), $options, $bubbleable_metadata);
+ $replacements += \Drupal::token()->generate('url', $url_tokens, ['url' => $entity->toUrl()], $options, $bubbleable_metadata);
}
// [entity:original:*] chained tokens.
if (($original_tokens = \Drupal::token()->findWithPrefix($tokens, 'original')) && _token_module($type, 'original') == 'token' && !empty($entity->original)) {
- $replacements += \Drupal::token()->generate($type, $original_tokens, array($type => $entity->original), $options, $bubbleable_metadata);
+ $replacements += \Drupal::token()->generate($type, $original_tokens, [$type => $entity->original], $options, $bubbleable_metadata);
}
// Pass through to an generic 'entity' token type generation.
- $entity_data = array(
+ $entity_data = [
'entity_type' => $entity_type,
'entity' => $entity,
'token_type' => $type,
- );
+ ];
// @todo Investigate passing through more data like everything from entity_extract_ids().
$replacements += \Drupal::token()->generate('entity', $tokens, $entity_data, $options, $bubbleable_metadata);
}
@@ -917,7 +917,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
$replacements[$original] = token_render_array($reversed, $options);
break;
case 'join':
- $replacements[$original] = token_render_array($array, array('join' => '') + $options);
+ $replacements[$original] = token_render_array($array, ['join' => ''] + $options);
break;
}
}
@@ -934,18 +934,18 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
// [array:join:*] dynamic tokens.
if ($join_tokens = \Drupal::token()->findWithPrefix($tokens, 'join')) {
foreach ($join_tokens as $join => $original) {
- $replacements[$original] = token_render_array($array, array('join' => $join) + $options);
+ $replacements[$original] = token_render_array($array, ['join' => $join] + $options);
}
}
// [array:keys:*] chained tokens.
if ($key_tokens = \Drupal::token()->findWithPrefix($tokens, 'keys')) {
- $replacements += \Drupal::token()->generate('array', $key_tokens, array('array' => $keys), $options, $bubbleable_metadata);
+ $replacements += \Drupal::token()->generate('array', $key_tokens, ['array' => $keys], $options, $bubbleable_metadata);
}
// [array:reversed:*] chained tokens.
if ($reversed_tokens = \Drupal::token()->findWithPrefix($tokens, 'reversed')) {
- $replacements += \Drupal::token()->generate('array', $reversed_tokens, array('array' => array_reverse($array, TRUE)), array('array sort' => FALSE) + $options, $bubbleable_metadata);
+ $replacements += \Drupal::token()->generate('array', $reversed_tokens, ['array' => array_reverse($array, TRUE)], ['array sort' => FALSE] + $options, $bubbleable_metadata);
}
// @todo Handle if the array values are not strings and could be chained.
@@ -977,7 +977,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
if (empty($data[$type]) && ($entity_type = \Drupal::service('token.entity_mapper')->getEntityTypeForTokenType($type)) && $entity_type != $type && !empty($data[$entity_type]) && empty($options['recursive'])) {
$data[$type] = $data[$entity_type];
$options['recursive'] = TRUE;
- $replacements += \Drupal::moduleHandler()->invokeAll('tokens', array($type, $tokens, $data, $options, $bubbleable_metadata));
+ $replacements += \Drupal::moduleHandler()->invokeAll('tokens', [$type, $tokens, $data, $options, $bubbleable_metadata]);
}
// If the token type specifics a 'needs-data' value, and the value is not
@@ -986,7 +986,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
// Only check when tests are running.
$type_info = \Drupal::token()->getTypeInfo($type);
if (!empty($type_info['needs-data']) && !isset($data[$type_info['needs-data']])) {
- trigger_error(t('Attempting to perform token replacement for token type %type without required data', array('%type' => $type)), E_USER_WARNING);
+ trigger_error(t('Attempting to perform token replacement for token type %type without required data', ['%type' => $type]), E_USER_WARNING);
}
}
@@ -997,50 +997,50 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
* Implements hook_token_info() on behalf of book.module.
*/
function book_token_info() {
- $info['types']['book'] = array(
+ $info['types']['book'] = [
'name' => t('Book'),
'description' => t('Tokens related to books.'),
'needs-data' => 'book',
- );
+ ];
- $info['tokens']['book']['title'] = array(
+ $info['tokens']['book']['title'] = [
'name' => t('Title'),
'description' => t('Title of the book.'),
- );
- $info['tokens']['book']['author'] = array(
+ ];
+ $info['tokens']['book']['author'] = [
'name' => t('Author'),
'description' => t('The author of the book.'),
'type' => 'user',
- );
- $info['tokens']['book']['root'] = array(
+ ];
+ $info['tokens']['book']['root'] = [
'name' => t('Root'),
'description' => t('Top level of the book.'),
'type' => 'node',
- );
- $info['tokens']['book']['parent'] = array(
+ ];
+ $info['tokens']['book']['parent'] = [
'name' => t('Parent'),
'description' => t('Parent of the current page.'),
'type' => 'node',
- );
- $info['tokens']['book']['parents'] = array(
+ ];
+ $info['tokens']['book']['parents'] = [
'name' => t('Parents'),
'description' => t("An array of all the node's parents, starting with the root."),
'type' => 'array',
- );
+ ];
- $info['tokens']['node']['book'] = array(
+ $info['tokens']['node']['book'] = [
'name' => t('Book'),
'description' => t('The book page associated with the node.'),
'type' => 'book',
- );
+ ];
return $info;
}
/**
* Implements hook_tokens() on behalf of book.module.
*/
-function book_tokens($type, $tokens, array $data = array(), array $options = array(), BubbleableMetadata $bubbleable_metadata) {
- $replacements = array();
+function book_tokens($type, $tokens, array $data = [], array $options = [], BubbleableMetadata $bubbleable_metadata) {
+ $replacements = [];
// Node tokens.
if ($type == 'node' && !empty($data['node'])) {
@@ -1049,7 +1049,7 @@ function book_tokens($type, $tokens, array $data = array(), array $options = arr
if (!empty($book['bid'])) {
if ($book_tokens = \Drupal::token()->findWithPrefix($tokens, 'book')) {
$child_node = Node::load($book['nid']);
- $replacements += \Drupal::token()->generate('book', $book_tokens, array('book' => $child_node), $options, $bubbleable_metadata);
+ $replacements += \Drupal::token()->generate('book', $book_tokens, ['book' => $child_node], $options, $bubbleable_metadata);
}
}
}
@@ -1081,18 +1081,18 @@ function book_tokens($type, $tokens, array $data = array(), array $options = arr
}
if ($book_tokens = \Drupal::token()->findWithPrefix($tokens, 'author')) {
- $replacements += \Drupal::token()->generate('user', $book_tokens, array('user' => $book_node->getOwner()), $options, $bubbleable_metadata);
+ $replacements += \Drupal::token()->generate('user', $book_tokens, ['user' => $book_node->getOwner()], $options, $bubbleable_metadata);
}
if ($book_tokens = \Drupal::token()->findWithPrefix($tokens, 'root')) {
- $replacements += \Drupal::token()->generate('node', $book_tokens, array('node' => $book_node), $options, $bubbleable_metadata);
+ $replacements += \Drupal::token()->generate('node', $book_tokens, ['node' => $book_node], $options, $bubbleable_metadata);
}
if (!empty($book['pid']) && $book_tokens = \Drupal::token()->findWithPrefix($tokens, 'parent')) {
$parent_node = Node::load($book['pid']);
- $replacements += \Drupal::token()->generate('node', $book_tokens, array('node' => $parent_node), $options, $bubbleable_metadata);
+ $replacements += \Drupal::token()->generate('node', $book_tokens, ['node' => $parent_node], $options, $bubbleable_metadata);
}
if ($book_tokens = \Drupal::token()->findWithPrefix($tokens, 'parents')) {
$parents = token_book_load_all_parents($book);
- $replacements += \Drupal::token()->generate('array', $book_tokens, array('array' => $parents), $options, $bubbleable_metadata);
+ $replacements += \Drupal::token()->generate('array', $book_tokens, ['array' => $parents], $options, $bubbleable_metadata);
}
}
}
@@ -1105,46 +1105,46 @@ function book_tokens($type, $tokens, array $data = array(), array $options = arr
*/
function menu_ui_token_info() {
// Menu tokens.
- $info['types']['menu'] = array(
+ $info['types']['menu'] = [
'name' => t('Menus'),
'description' => t('Tokens related to menus.'),
'needs-data' => 'menu',
- );
- $info['tokens']['menu']['name'] = array(
+ ];
+ $info['tokens']['menu']['name'] = [
'name' => t('Name'),
'description' => t("The name of the menu."),
- );
- $info['tokens']['menu']['machine-name'] = array(
+ ];
+ $info['tokens']['menu']['machine-name'] = [
'name' => t('Machine-readable name'),
'description' => t("The unique machine-readable name of the menu."),
- );
- $info['tokens']['menu']['description'] = array(
+ ];
+ $info['tokens']['menu']['description'] = [
'name' => t('Description'),
'description' => t('The optional description of the menu.'),
- );
- $info['tokens']['menu']['menu-link-count'] = array(
+ ];
+ $info['tokens']['menu']['menu-link-count'] = [
'name' => t('Menu link count'),
'description' => t('The number of menu links belonging to the menu.'),
- );
- $info['tokens']['menu']['edit-url'] = array(
+ ];
+ $info['tokens']['menu']['edit-url'] = [
'name' => t('Edit URL'),
'description' => t("The URL of the menu's edit page."),
- );
+ ];
- $info['tokens']['menu-link']['menu'] = array(
+ $info['tokens']['menu-link']['menu'] = [
'name' => t('Menu'),
'description' => t('The menu of the menu link.'),
'type' => 'menu',
- );
- $info['tokens']['menu-link']['edit-url'] = array(
+ ];
+ $info['tokens']['menu-link']['edit-url'] = [
'name' => t('Edit URL'),
'description' => t("The URL of the menu link's edit page."),
- );
- $info['tokens']['node']['menu-link'] = array(
+ ];
+ $info['tokens']['node']['menu-link'] = [
'name' => t('Menu link'),
'description' => t("The menu link for this node."),
'type' => 'menu-link',
- );
+ ];
return $info;
}
@@ -1152,13 +1152,13 @@ function menu_ui_token_info() {
/**
* Implements hook_tokens() on behalf of menu_ui.module.
*/
-function menu_ui_tokens($type, $tokens, array $data = array(), array $options = array(), BubbleableMetadata $bubbleable_metadata) {
- $replacements = array();
+function menu_ui_tokens($type, $tokens, array $data = [], array $options = [], BubbleableMetadata $bubbleable_metadata) {
+ $replacements = [];
/** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
$menu_link_manager = \Drupal::service('plugin.manager.menu.link');
- $url_options = array('absolute' => TRUE);
+ $url_options = ['absolute' => TRUE];
if (isset($options['langcode'])) {
$url_options['language'] = \Drupal::languageManager()->getLanguage($options['langcode']);
$langcode = $options['langcode'];
@@ -1196,13 +1196,13 @@ function menu_ui_tokens($type, $tokens, array $data = array(), array $options =
if ($menu_tokens = \Drupal::token()->findWithPrefix($tokens, 'menu-link')) {
if ($node->getFieldDefinition('menu_link') && $menu_link = $node->menu_link->entity) {
/** @var \Drupal\menu_link_content\MenuLinkContentInterface $menu_link */
- $replacements += \Drupal::token()->generate('menu-link', $menu_tokens, array('menu-link' => $menu_link), $options, $bubbleable_metadata);
+ $replacements += \Drupal::token()->generate('menu-link', $menu_tokens, ['menu-link' => $menu_link], $options, $bubbleable_metadata);
}
else {
$url = $node->urlInfo();
if ($links = $menu_link_manager->loadLinksByRoute($url->getRouteName(), $url->getRouteParameters())) {
$link = _token_menu_link_best_match($node, $links);
- $replacements += \Drupal::token()->generate('menu-link', $menu_tokens, array('menu-link' => $link), $options, $bubbleable_metadata);
+ $replacements += \Drupal::token()->generate('menu-link', $menu_tokens, ['menu-link' => $link], $options, $bubbleable_metadata);
}
}
}
@@ -1234,7 +1234,7 @@ function menu_ui_tokens($type, $tokens, array $data = array(), array $options =
// Chained token relationships.
if (($menu_tokens = \Drupal::token()->findWithPrefix($tokens, 'menu')) && $menu = Menu::load($link->getMenuName())) {
- $replacements += \Drupal::token()->generate('menu', $menu_tokens, array('menu' => $menu), $options, $bubbleable_metadata);
+ $replacements += \Drupal::token()->generate('menu', $menu_tokens, ['menu' => $menu], $options, $bubbleable_metadata);
}
}
@@ -1370,13 +1370,13 @@ function field_token_info_alter(&$info) {
$cardinality = $field->getCardinality();
$cardinality = ($cardinality == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED || $cardinality > 3) ? 3 : $cardinality;
$field_token_name = $token_type . '-' . $field_name;
- $info['tokens'][$token_type][$field_name] = array(
+ $info['tokens'][$token_type][$field_name] = [
'name' => Html::escape($label),
'description' => $description,
'module' => 'token',
// For multivalue fields the field token is a list type.
'type' => $cardinality > 1 ? "list<$field_token_name>" : $field_token_name,
- );
+ ];
// Field token type.
$info['types'][$field_token_name] = [
@@ -1387,12 +1387,12 @@ function field_token_info_alter(&$info) {
];
// Field list token type.
if ($cardinality > 1) {
- $info['types']["list<$field_token_name>"] = array(
- 'name' => t('List of @type values', array('@type' => Html::escape($label))),
- 'description' => t('Tokens for lists of @type values.', array('@type' => Html::escape($label))),
+ $info['types']["list<$field_token_name>"] = [
+ 'name' => t('List of @type values', ['@type' => Html::escape($label)]),
+ 'description' => t('Tokens for lists of @type values.', ['@type' => Html::escape($label)]),
'needs-data' => "list<$field_token_name>",
'nested' => TRUE,
- );
+ ];
}
// Show a different token for each field delta.
@@ -1488,8 +1488,8 @@ function _token_field_label($entity_type, $field_name) {
/**
* Implements hook_tokens() on behalf of field.module.
*/
-function field_tokens($type, $tokens, array $data = array(), array $options = array(), BubbleableMetadata $bubbleable_metadata) {
- $replacements = array();
+function field_tokens($type, $tokens, array $data = [], array $options = [], BubbleableMetadata $bubbleable_metadata) {
+ $replacements = [];
$langcode = isset($options['langcode']) ? $options['langcode'] : NULL;
// Entity tokens.
if ($type == 'entity' && !empty($data['entity_type']) && !empty($data['entity']) && !empty($data['token_type'])) {
@@ -1713,7 +1713,7 @@ function token_pre_render_field_token($elements) {
foreach ($deltas as $index => $delta) {
// Do not add a suffix to the last item.
if ($index < ($count - 1)) {
- $elements[$delta] += array('#suffix' => $join);
+ $elements[$delta] += ['#suffix' => $join];
}
}
}