diff --git a/core/modules/views/src/Plugin/views/PluginBase.php b/core/modules/views/src/Plugin/views/PluginBase.php index e56dcae..2fe69dc 100644 --- a/core/modules/views/src/Plugin/views/PluginBase.php +++ b/core/modules/views/src/Plugin/views/PluginBase.php @@ -376,13 +376,20 @@ 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' => $twig_tokens, + '#context' => $vars, '#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 251d025..14558b2 100644 --- a/core/modules/views/src/Plugin/views/field/Field.php +++ b/core/modules/views/src/Plugin/views/field/Field.php @@ -913,19 +913,28 @@ protected function addSelfTokens(&$tokens, $item) { // Use \Drupal\Component\Utility\Xss::filterAdmin() because it's user data // and we can't be sure it is safe. We know nothing about the data, // though, so we can't really do much else. - if (isset($item['raw'])) { // If $item['raw'] is an array then we can use as is, if it's an object - // we cast it to an array, if it's neither, we can't use it. - $raw = is_array($item['raw']) ? $item['raw'] : - (is_object($item['raw']) ? (array)$item['raw'] : NULL); + // we have to process it differently. If it's neither, we can't use it. + $raw = $item['raw']; } - if (isset($raw) && isset($raw[$id]) && is_scalar($raw[$id])) { - $tokens['{{ ' . $this->options['id'] . '-' . $id . ' }}'] = CoreXss::filterAdmin($raw[$id]); + if ($raw && is_array($raw)) { + if ($raw !== NULL && isset($raw[$id]) && is_scalar($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 . ' }}'] = ''; + } } - else { - // Make sure that empty values are replaced as well. - $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); + } + else { + // Make sure that empty values are replaced as well. + $tokens['{{ ' . $this->options['id'] . '-' . $id . ' }}'] = ''; + } } } }