diff --git a/core/modules/taxonomy/src/Plugin/views/field/TaxonomyIndexTid.php b/core/modules/taxonomy/src/Plugin/views/field/TaxonomyIndexTid.php index 4fab01c..0ec6dc7 100644 --- a/core/modules/taxonomy/src/Plugin/views/field/TaxonomyIndexTid.php +++ b/core/modules/taxonomy/src/Plugin/views/field/TaxonomyIndexTid.php @@ -169,16 +169,15 @@ function render_item($count, $item) { } protected function documentSelfTokens(&$tokens) { - $tokens['[' . $this->options['id'] . '-tid' . ']'] = $this->t('The taxonomy term ID for the term.'); - $tokens['[' . $this->options['id'] . '-name' . ']'] = $this->t('The taxonomy term name for the term.'); - $tokens['[' . $this->options['id'] . '-vocabulary-vid' . ']'] = $this->t('The machine name for the vocabulary the term belongs to.'); - $tokens['[' . $this->options['id'] . '-vocabulary' . ']'] = $this->t('The name for the vocabulary the term belongs to.'); + $tokens['[' . $this->options['id'] . '__tid' . ']'] = $this->t('The taxonomy term ID for the term.'); + $tokens['[' . $this->options['id'] . '__name' . ']'] = $this->t('The taxonomy term name for the term.'); + $tokens['[' . $this->options['id'] . '__vocabulary_vid' . ']'] = $this->t('The machine name for the vocabulary the term belongs to.'); + $tokens['[' . $this->options['id'] . '__vocabulary' . ']'] = $this->t('The name for the vocabulary the term belongs to.'); } protected function addSelfTokens(&$tokens, $item) { foreach (array('tid', 'name', 'vocabulary_vid', 'vocabulary') as $token) { - // Replace _ with - for the vocabulary vid. - $tokens['[' . $this->options['id'] . '-' . str_replace('_', '-', $token) . ']'] = isset($item[$token]) ? $item[$token] : ''; + $tokens['[' . $this->options['id'] . '__' . $token . ']'] = isset($item[$token]) ? $item[$token] : ''; } } diff --git a/core/modules/user/src/Plugin/views/field/Roles.php b/core/modules/user/src/Plugin/views/field/Roles.php index 403e9a4..03e2adf 100644 --- a/core/modules/user/src/Plugin/views/field/Roles.php +++ b/core/modules/user/src/Plugin/views/field/Roles.php @@ -101,14 +101,14 @@ function render_item($count, $item) { } protected function documentSelfTokens(&$tokens) { - $tokens['[' . $this->options['id'] . '-role' . ']'] = $this->t('The name of the role.'); - $tokens['[' . $this->options['id'] . '-rid' . ']'] = $this->t('The role machine-name of the role.'); + $tokens['[' . $this->options['id'] . '__role' . ']'] = $this->t('The name of the role.'); + $tokens['[' . $this->options['id'] . '__rid' . ']'] = $this->t('The role machine-name of the role.'); } protected function addSelfTokens(&$tokens, $item) { if (!empty($item['role'])) { - $tokens['[' . $this->options['id'] . '-role' . ']'] = $item['role']; - $tokens['[' . $this->options['id'] . '-rid' . ']'] = $item['rid']; + $tokens['[' . $this->options['id'] . '__role' . ']'] = $item['role']; + $tokens['[' . $this->options['id'] . '__rid' . ']'] = $item['rid']; } } diff --git a/core/modules/views/src/Plugin/views/PluginBase.php b/core/modules/views/src/Plugin/views/PluginBase.php index 2fe69dc..e56dcae 100644 --- a/core/modules/views/src/Plugin/views/PluginBase.php +++ b/core/modules/views/src/Plugin/views/PluginBase.php @@ -376,20 +376,13 @@ protected function viewsTokenReplace($text, $tokens) { // through an inline template for rendering and replacement. $text = strtr($text, $other_tokens); if ($twig_tokens) { - // Rename the token keys so they are valid twig variable names. - $vars = []; - foreach ($twig_tokens as $token => $value) { - $new_token = str_replace('-', '__', $token); - $vars[$new_token] = $value; - $text = str_replace($token, $new_token, $text); - } // Use the unfiltered text for the Twig template, then filter the output. // Otherwise, Xss::filterAdmin could remove valid Twig syntax before the // template is parsed. $build = array( '#type' => 'inline_template', '#template' => $text, - '#context' => $vars, + '#context' => $twig_tokens, '#post_render' => [ function ($children, $elements) { return Xss::filterAdmin($children); diff --git a/core/modules/views/src/Plugin/views/field/Field.php b/core/modules/views/src/Plugin/views/field/Field.php index 14558b2..ae67c95 100644 --- a/core/modules/views/src/Plugin/views/field/Field.php +++ b/core/modules/views/src/Plugin/views/field/Field.php @@ -903,7 +903,7 @@ function render_item($count, $item) { protected function documentSelfTokens(&$tokens) { $field = $this->getFieldDefinition(); foreach ($field->getColumns() as $id => $column) { - $tokens['{{ ' . $this->options['id'] . '-' . $id . ' }}'] = $this->t('Raw @column', array('@column' => $id)); + $tokens['{{ ' . $this->options['id'] . '__' . $id . ' }}'] = $this->t('Raw @column', array('@column' => $id)); } } @@ -920,20 +920,20 @@ protected function addSelfTokens(&$tokens, $item) { } if ($raw && is_array($raw)) { if ($raw !== NULL && isset($raw[$id]) && is_scalar($raw[$id])) { - $tokens['{{ ' . $this->options['id'] . '-' . $id . ' }}'] = CoreXss::filterAdmin($raw[$id]); + $tokens['{{ ' . $this->options['id'] . '__' . $id . ' }}'] = CoreXss::filterAdmin($raw[$id]); } else { // Make sure that empty values are replaced as well. - $tokens['{{ ' . $this->options['id'] . '-' . $id . ' }}'] = ''; + $tokens['{{ ' . $this->options['id'] . '__' . $id . ' }}'] = ''; } } else if($raw && is_object($raw)) { if ($raw !== NULL && isset($raw->$id) && is_scalar($raw->$id)) { - $tokens['{{ ' . $this->options['id'] . '-' . $id . ' }}'] = CoreXss::filterAdmin($raw->$id); + $tokens['{{ ' . $this->options['id'] . '__' . $id . ' }}'] = CoreXss::filterAdmin($raw->$id); } else { // Make sure that empty values are replaced as well. - $tokens['{{ ' . $this->options['id'] . '-' . $id . ' }}'] = ''; + $tokens['{{ ' . $this->options['id'] . '__' . $id . ' }}'] = ''; } } } diff --git a/core/modules/views/src/Plugin/views/field/FieldPluginBase.php b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php index ee16994..0370bbf 100644 --- a/core/modules/views/src/Plugin/views/field/FieldPluginBase.php +++ b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php @@ -1634,10 +1634,10 @@ protected function getTokenValuesRecursive(array $array, array $parent_keys = ar * fields as a list. For example, the field that displays all terms * on a node might have tokens for the tid and the term. * - * By convention, tokens should follow the format of {{ token-subtoken }} + * By convention, tokens should follow the format of {{ token__subtoken }} * where token is the field ID and subtoken is the field. If the - * field ID is terms, then the tokens might be {{ terms-tid }} and - * {{ terms-name }}. + * field ID is terms, then the tokens might be {{ terms__tid }} and + * {{ terms__name }}. */ protected function addSelfTokens(&$tokens, $item) { } diff --git a/core/modules/views/tests/modules/views_test_data/src/Plugin/views/field/FieldTest.php b/core/modules/views/tests/modules/views_test_data/src/Plugin/views/field/FieldTest.php index 74d5d3d..0f8feef 100644 --- a/core/modules/views/tests/modules/views_test_data/src/Plugin/views/field/FieldTest.php +++ b/core/modules/views/tests/modules/views_test_data/src/Plugin/views/field/FieldTest.php @@ -46,7 +46,7 @@ public function getTestValue() { * Overrides Drupal\views\Plugin\views\field\FieldPluginBase::addSelfTokens(). */ protected function addSelfTokens(&$tokens, $item) { - $tokens['[test-token]'] = $this->getTestValue(); + $tokens['[test__token]'] = $this->getTestValue(); } /**