Skip to content
Snippets Groups Projects
Commit 1be30c5a authored by Brian Canini's avatar Brian Canini
Browse files

Merge branch 'token' into module-updates-rc

parents 75a0f306 0da4963c
No related branches found
No related tags found
No related merge requests found
Showing
with 134 additions and 83 deletions
......@@ -7746,17 +7746,17 @@
},
{
"name": "drupal/token",
"version": "1.7.0",
"version": "1.9.0",
"source": {
"type": "git",
"url": "https://git.drupalcode.org/project/token.git",
"reference": "8.x-1.7"
"reference": "8.x-1.9"
},
"dist": {
"type": "zip",
"url": "https://ftp.drupal.org/files/projects/token-8.x-1.7.zip",
"reference": "8.x-1.7",
"shasum": "c7e3a3757282e4c94e3c1fff08d01e22155cb853"
"url": "https://ftp.drupal.org/files/projects/token-8.x-1.9.zip",
"reference": "8.x-1.9",
"shasum": "a5d234382a1a0e4ba61d4c7a2fa10671ca656be4"
},
"require": {
"drupal/core": "^8.8 || ^9"
......@@ -7764,8 +7764,8 @@
"type": "drupal-module",
"extra": {
"drupal": {
"version": "8.x-1.7",
"datestamp": "1589314266",
"version": "8.x-1.9",
"datestamp": "1608284866",
"security-coverage": {
"status": "covered",
"message": "Covered by Drupal's security advisory policy"
......@@ -7779,7 +7779,7 @@
},
"notification-url": "https://packages.drupal.org/8/downloads",
"license": [
"GPL-2.0+"
"GPL-2.0-or-later"
],
"authors": [
{
......
......@@ -7985,18 +7985,18 @@
},
{
"name": "drupal/token",
"version": "1.7.0",
"version_normalized": "1.7.0.0",
"version": "1.9.0",
"version_normalized": "1.9.0.0",
"source": {
"type": "git",
"url": "https://git.drupalcode.org/project/token.git",
"reference": "8.x-1.7"
"reference": "8.x-1.9"
},
"dist": {
"type": "zip",
"url": "https://ftp.drupal.org/files/projects/token-8.x-1.7.zip",
"reference": "8.x-1.7",
"shasum": "c7e3a3757282e4c94e3c1fff08d01e22155cb853"
"url": "https://ftp.drupal.org/files/projects/token-8.x-1.9.zip",
"reference": "8.x-1.9",
"shasum": "a5d234382a1a0e4ba61d4c7a2fa10671ca656be4"
},
"require": {
"drupal/core": "^8.8 || ^9"
......@@ -8004,8 +8004,8 @@
"type": "drupal-module",
"extra": {
"drupal": {
"version": "8.x-1.7",
"datestamp": "1589314266",
"version": "8.x-1.9",
"datestamp": "1608284866",
"security-coverage": {
"status": "covered",
"message": "Covered by Drupal's security advisory policy"
......@@ -8020,7 +8020,7 @@
"installation-source": "dist",
"notification-url": "https://packages.drupal.org/8/downloads",
"license": [
"GPL-2.0+"
"GPL-2.0-or-later"
],
"authors": [
{
......
{
"name": "drupal/token",
"type": "drupal-module",
"license": "GPL-2.0+",
"license": "GPL-2.0-or-later",
"description": "Provides a user interface for the Token API, some missing core tokens.",
"require": {
"drupal/core": "^8.7.7 || ^9"
},
"extra": {
"drush": {
"services": {
......
services:
devel.command:
token.commands:
class: Drupal\token\Commands\TokenCommands
arguments:
- '@module_handler'
......
......@@ -72,10 +72,6 @@ public function buildRenderable(array $token_types, array $options = []) {
];
// @todo Find a way to use the render cache for this.
/*if ($cached_output = token_render_cache_get($element)) {
return $cached_output;
}*/
$tree_options = [
'flat' => TRUE,
'restricted' => $options['show_restricted'],
......@@ -232,7 +228,8 @@ protected function getTokenData($token_type, array $options) {
// parent.
$token_parents[] = $token_type;
}
elseif (in_array($token, array_slice($token_parents, 1), TRUE)) {
// The 'entity' token will be repeated on nested entity reference fields.
elseif ($token !== 'entity' && in_array($token, array_slice($token_parents, 1), TRUE)) {
// Prevent duplicate recursive tokens. For example, this will prevent
// the tree from generating the following tokens or deeper:
// [comment:parent:parent]
......
......@@ -4,16 +4,47 @@
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\Request;
use Drupal\token\TokenInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Controller for token module test.
*/
class TokenTreeBrowseController extends ControllerBase {
/**
* Service to retrieve token information.
*
* @var \Drupal\token\TokenInterface
*/
protected $token;
/**
* The construct method.
*
* @param \Drupal\token\TokenInterface $token
* The token.
*/
public function __construct(TokenInterface $token) {
$this->token = $token;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('token')
);
}
/**
* Page callback to output a link.
*/
function outputLink(Request $request) {
public function outputLink(Request $request) {
$build['tree']['#theme'] = 'token_tree_link';
$build['tokenarea'] = [
'#markup' => \Drupal::token()->replace('[current-page:title]'),
'#markup' => $this->token->replace('[current-page:title]'),
'#type' => 'markup',
];
return $build;
......
......@@ -5,7 +5,7 @@ package: Testing
core_version_requirement: ^8.7.7 || ^9
hidden: TRUE
# Information added by Drupal.org packaging script on 2020-04-26
version: '8.x-1.7'
# Information added by Drupal.org packaging script on 2020-12-18
version: '8.x-1.9'
project: 'token'
datestamp: 1587893591
datestamp: 1608284868
......@@ -7,7 +7,7 @@ hidden: TRUE
dependencies:
- drupal:image
# Information added by Drupal.org packaging script on 2020-04-26
version: '8.x-1.7'
# Information added by Drupal.org packaging script on 2020-12-18
version: '8.x-1.9'
project: 'token'
datestamp: 1587893591
datestamp: 1608284868
......@@ -51,9 +51,9 @@ public function testBlockTitleTokens() {
$this->drupalGet($block->toUrl());
// Ensure that the link to available tokens is present and correctly
// positioned.
$this->assertLink('Browse available tokens.');
$this->assertSession()->linkExists('Browse available tokens.');
$this->assertText('This field supports tokens. Browse available tokens.');
$this->drupalPostForm(NULL, [], t('Save block'));
$this->drupalPostForm(NULL, [], 'Save block');
// Ensure token validation is working on the block.
$this->assertText('Title is using the following invalid tokens: [user:name].');
......@@ -68,6 +68,6 @@ public function testBlockTitleTokens() {
$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");
$this->assertSession()->responseContains("Site's first node block title");
}
}
......@@ -23,7 +23,7 @@ function testCurrentPageTokens() {
// initial request.
$this->rebuildAll();
$tokens = [
'[current-page:title]' => t('Log in'),
'[current-page:title]' => 'Log in',
'[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(),
......
......@@ -104,11 +104,11 @@ public function testFileFieldUi() {
$this->drupalGet('admin/structure/types/manage/article/fields/node.article.field_image');
// Ensure the 'Browse available tokens' link is present and correct.
$this->assertLink('Browse available tokens.');
$this->assertLinkByHref('token/tree');
$this->assertSession()->linkExists('Browse available tokens.');
$this->assertSession()->linkByHrefExists('token/tree');
// Ensure that the default file directory value validates correctly.
$this->drupalPostForm(NULL, [], t('Save settings'));
$this->drupalPostForm(NULL, [], 'Save settings');
$this->assertText(t('Saved Image configuration.'));
}
......
......@@ -136,7 +136,7 @@ function testMenuTokens() {
// Regression test for http://drupal.org/node/1317926 to ensure the
// original node object is not changed when calling menu_node_prepare().
$this->assertTrue(!isset($loaded_node->menu), t('The $node->menu property was not modified during token replacement.'), 'Regression');
$this->assertTrue(!isset($loaded_node->menu), 'The $node->menu property was not modified during token replacement.', 'Regression');
// Now add a node with a menu-link from the UI and ensure it works.
$this->drupalLogin($this->drupalCreateUser([
......@@ -153,7 +153,7 @@ function testMenuTokens() {
'menu_options[main]' => 1,
'menu_parent' => 'main-menu:',
];
$this->drupalPostForm('admin/structure/types/manage/page', $edit, t('Save content type'));
$this->drupalPostForm('admin/structure/types/manage/page', $edit, 'Save content type');
// Use a menu-link token in the body.
$this->drupalGet('node/add/page');
......@@ -164,17 +164,17 @@ function testMenuTokens() {
'body[0][value]' => 'This is a [node:menu-link:title] token to the menu link title',
'menu[enabled]' => 1,
'menu[title]' => 'Test preview',
], t('Save'));
], 'Save');
$node = $this->drupalGetNodeByTitle('Node menu title test');
$this->assertEquals('This is a Test preview token to the menu link title', $node->body->value);
// Disable the menu link, save the node and verify that the menu link is
// no longer displayed.
$link = menu_ui_get_menu_link_defaults($node);
$this->drupalPostForm('admin/structure/menu/manage/main-menu', ['links[menu_plugin_id:' . $link['id'] . '][enabled]' => FALSE], t('Save'));
$this->drupalPostForm('admin/structure/menu/manage/main-menu', ['links[menu_plugin_id:' . $link['id'] . '][enabled]' => FALSE], 'Save');
$this->assertText('Menu Main menu has been updated.');
$this->drupalPostForm('node/' . $node->id() . '/edit', [], t('Save'));
$this->assertNoLink('Test preview');
$this->drupalPostForm('node/' . $node->id() . '/edit', [], 'Save');
$this->assertSession()->linkNotExists('Test preview');
// Now test a parent link and token.
$this->drupalGet('node/add/page');
......@@ -196,7 +196,7 @@ function testMenuTokens() {
'menu[enabled]' => 1,
'menu[title]' => 'Child link',
'menu[menu_parent]' => 'main-menu:' . $parent_link->getPluginId(),
], t('Save'));
], 'Save');
$node = $this->drupalGetNodeByTitle('Node menu title parent path test');
$this->assertEquals('This is a /admin/config token to the menu link parent', $node->body->value);
......@@ -205,7 +205,7 @@ function testMenuTokens() {
'menu[menu_parent]' => 'main-menu:' . $node_link->getPluginId(),
'title[0][value]' => 'Node menu title edit parent path test',
'body[0][value]' => 'This is a [node:menu-link:parent:url:path] token to the menu link parent',
], t('Save'));
], 'Save');
$node = $this->drupalGetNodeByTitle('Node menu title edit parent path test', TRUE);
$this->assertEquals(sprintf('This is a /node/%d token to the menu link parent', $loaded_node->id()), $node->body->value);
......@@ -229,7 +229,7 @@ function testMenuTokens() {
'title[0][value]' => 'Node menu adding menu later test',
'body[0][value]' => 'Going to add a menu link on edit',
'menu[enabled]' => 0,
], t('Save'));
], 'Save');
$node = $this->drupalGetNodeByTitle('Node menu adding menu later test');
// Now edit it and add a menu item.
$this->drupalGet('node/' . $node->id() . '/edit');
......@@ -239,12 +239,12 @@ function testMenuTokens() {
'menu[enabled]' => 1,
'menu[title]' => 'Child link',
'menu[menu_parent]' => 'main-menu:' . $parent_link->getPluginId(),
], t('Save'));
], 'Save');
$node = $this->drupalGetNodeByTitle('Node menu adding menu later test', TRUE);
$this->assertEquals('This is a /admin/config token to the menu link parent', $node->body->value);
// And make sure the menu link exists with the right URI.
$link = menu_ui_get_menu_link_defaults($node);
$this->assertTrue(!empty($link['entity_id']));
$this->assertNotEmpty($link['entity_id']);
$query = \Drupal::entityQuery('menu_link_content')
->condition('link.uri', 'entity:node/' . $node->id())
->sort('id', 'ASC')
......@@ -260,7 +260,7 @@ function testMenuTokens() {
'menu[enabled]' => 1,
'menu[title]' => 'menu link provided by node',
];
$this->drupalPostForm('node/add/page', $edit, t('Save'));
$this->drupalPostForm('node/add/page', $edit, 'Save');
$this->assertText('page ' . $node_title . ' has been created');
$node = $this->drupalGetNodeByTitle($node_title);
......@@ -328,7 +328,7 @@ function testMultilingualMenu() {
'settings[node][article][fields][title]' => TRUE,
'settings[menu_link_content][menu_link_content][translatable]' => TRUE,
];
$this->drupalPostForm(NULL, $edit, t('Save configuration'));
$this->drupalPostForm(NULL, $edit, 'Save configuration');
$this->assertText('Settings successfully updated.');
// Create an english node with an english menu.
......@@ -338,7 +338,7 @@ function testMultilingualMenu() {
'menu[enabled]' => TRUE,
'menu[title]' => 'English menu title',
];
$this->drupalPostForm('/node/add/article', $edit, t('Save'));
$this->drupalPostForm('/node/add/article', $edit, 'Save');
$this->assertText('English test node with menu has been created.');
// Add a german translation.
......@@ -349,14 +349,14 @@ function testMultilingualMenu() {
'menu[enabled]' => TRUE,
'menu[title]' => 'German menu title',
];
$this->drupalPostForm(NULL, $edit, t('Save (this translation)'));
$this->drupalPostForm(NULL, $edit, 'Save (this translation)');
$this->assertText('German test node with menu has been updated.');
// Verify that the menu links are correct.
$this->drupalGet('node/1');
$this->assertLink('English menu title');
$this->assertSession()->linkExists('English menu title');
$this->drupalGet('de/node/1');
$this->assertLink('German menu title');
$this->assertSession()->linkExists('German menu title');
// Verify that tokens are correct.
$node = Node::load(1);
......@@ -456,4 +456,30 @@ public function testMenuLinkParentsToken() {
$this->assertNoTokens('menu-link', ['menu-link' => $child_1_1], ['parents']);
}
/**
* Tests that no menu link is generated when the node gets previewed.
*/
public function testPreviewMenuLink() {
$this->drupalCreateContentType(['type' => 'article']);
$permissions = [
'access administration pages',
'administer content types',
'create article content',
'edit any article content',
'administer menu',
];
$this->drupalLogin($this->drupalCreateUser($permissions));
// Create an english node with an english menu.
$this->drupalGet('/node/add/article');
$edit = [
'title[0][value]' => 'English test node with menu',
'menu[enabled]' => TRUE,
'menu[title]' => 'English menu title',
];
$this->drupalGet('node/add/article');
$this->submitForm($edit, 'Preview');
$menu_links = \Drupal::entityTypeManager()->getStorage('menu_link_content')->loadByProperties(['menu_name' => 'main']);
$this->assertEmpty($menu_links);
}
}
......@@ -25,7 +25,7 @@ function assertTokens($type, array $data, array $tokens, array $options = []) {
foreach ($tokens as $name => $expected) {
$token = $input[$name];
if (!isset($expected)) {
$this->assertTrue(!isset($replacements[$token]), t("Token value for @token was not generated.", ['@type' => $type, '@token' => $token]));
$this->assertArrayNotHasKey($token, $replacements, t("Token value for @token was not generated.", ['@token' => $token]));
}
elseif (!isset($replacements[$token])) {
$this->fail(t("Token value for @token was not generated.", ['@type' => $type, '@token' => $token]));
......
......@@ -62,14 +62,14 @@ public function testUserTokens() {
// Add a user picture to the account.
$image = current($this->getTestFiles('image'));
$edit = ['files[user_picture_0]' => \Drupal::service('file_system')->realpath($image->uri)];
$this->drupalPostForm('user/' . $this->account->id() . '/edit', $edit, t('Save'));
$this->drupalPostForm('user/' . $this->account->id() . '/edit', $edit, 'Save');
$storage = \Drupal::entityTypeManager()->getStorage('user');
// Load actual user data from database.
$storage->resetCache();
$this->account = $storage->load($this->account->id());
$this->assertTrue(!empty($this->account->user_picture->target_id), 'User picture uploaded.');
$this->assertNotEmpty($this->account->user_picture->target_id, 'User picture uploaded.');
$picture = [
'#theme' => 'user_picture',
......@@ -125,7 +125,7 @@ public function testUserTokens() {
public function testUserAccountSettings() {
$this->drupalGet('admin/config/people/accounts');
$this->assertText('The list of available tokens that can be used in e-mails is provided below.');
$this->assertLink('Browse available tokens.');
$this->assertLinkByHref('token/tree');
$this->assertSession()->linkExists('Browse available tokens.');
$this->assertSession()->linkByHrefExists('token/tree');
}
}
......@@ -32,10 +32,10 @@ public function testNodeAutocomplete() {
],
]));
$this->assertTrue(isset($response['[node:nid]']));
$this->assertTrue(isset($response['[node:author]']));
$this->assertTrue(isset($response['[node:url]']));
$this->assertTrue(isset($response['[node:url:']));
$this->assertArrayHasKey('[node:nid]', $response);
$this->assertArrayHasKey('[node:author]', $response);
$this->assertArrayHasKey('[node:url]', $response);
$this->assertArrayHasKey('[node:url:', $response);
$url = $url_prefix . 'Title of [node:url:';
$response = Json::decode($this->drupalGet($url, [
......@@ -44,8 +44,8 @@ public function testNodeAutocomplete() {
],
]));
$this->assertTrue(isset($response['[node:url:path]']));
$this->assertTrue(isset($response['[node:url:absolute]']));
$this->assertArrayHasKey('[node:url:path]', $response);
$this->assertArrayHasKey('[node:url:absolute]', $response);
}
/**
......@@ -61,10 +61,10 @@ public function testUserAutocomplete() {
],
]));
$this->assertTrue(isset($response['[user:uid]']));
$this->assertTrue(isset($response['[user:original]']));
$this->assertTrue(isset($response['[user:url]']));
$this->assertTrue(isset($response['[user:url:']));
$this->assertArrayHasKey('[user:uid]', $response);
$this->assertArrayHasKey('[user:original]', $response);
$this->assertArrayHasKey('[user:url]', $response);
$this->assertArrayHasKey('[user:url:', $response);
$url = $url_prefix . 'Title of [user:original:';
$response = Json::decode($this->drupalGet($url, [
......@@ -73,6 +73,6 @@ public function testUserAutocomplete() {
],
]));
$this->assertTrue(isset($response['[user:original:uid]']));
$this->assertArrayHasKey('[user:original:uid]', $response);
}
}
......@@ -37,7 +37,7 @@ protected function assertTokenGroup($token_group, $message = '') {
$message = "Token group $token_group found.";
}
$this->assertTrue(in_array($token_group, $groups), $message);
$this->assertContains($token_group, $groups, $message);
}
/**
......@@ -56,7 +56,7 @@ protected function assertTokenNotGroup($token_group, $message = '') {
$message = "Token group $token_group not found.";
}
$this->assertFalse(in_array($token_group, $groups), $message);
$this->assertNotContains($token_group, $groups, $message);
}
/**
......
......@@ -136,7 +136,7 @@ public function testNodeTokens() {
*/
protected function getTokenTreeUrl($options = []) {
$this->drupalGet('token_module_test/browse');
$this->assertTitle('Available Tokens | Drupal');
$this->assertSession()->titleEquals('Available Tokens | Drupal');
$links = $this->xpath('//a[contains(@href, :href)]/@href', [':href' => 'token/tree']);
$link = $this->getAbsoluteUrl(current($links)->getText());
if (!empty($options)) {
......
......@@ -35,7 +35,7 @@ protected function setUp() {
$this->installEntitySchema('comment');
$this->installSchema('comment', ['comment_entity_statistics']);
$node_type = NodeType::create(['type' => 'page', 'name' => t('Page')]);
$node_type = NodeType::create(['type' => 'page', 'name' => 'Page']);
$node_type->save();
$this->installConfig(['comment']);
......
......@@ -3,7 +3,7 @@ name: Token
description: Provides a user interface for the Token API and some missing core tokens.
core_version_requirement: ^8.8 || ^9
# Information added by Drupal.org packaging script on 2020-04-26
version: '8.x-1.7'
# Information added by Drupal.org packaging script on 2020-12-18
version: '8.x-1.9'
project: 'token'
datestamp: 1587893591
datestamp: 1608284868
......@@ -203,7 +203,7 @@ function token_update_token_text($text, $updates = [], $leading = '[', $trailing
$regex = '/' . preg_quote($leading, '/') . '([^\s]*)' . preg_quote($trailing, '/') . '/';
preg_match_all($regex, $text, $matches);
foreach ($matches[1] as $index => $old_token) {
foreach ($matches[1] as $old_token) {
if (isset($updates[$old_token])) {
$new_token = $updates[$old_token];
$text = str_replace("{$leading}{$old_token}{$trailing}", "[$new_token]", $text);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment