diff --git a/core/modules/views/src/Plugin/views/field/Field.php b/core/modules/views/src/Plugin/views/field/Field.php index 251d025..98f1a59 100644 --- a/core/modules/views/src/Plugin/views/field/Field.php +++ b/core/modules/views/src/Plugin/views/field/Field.php @@ -7,7 +7,7 @@ namespace Drupal\views\Plugin\views\field; -use Drupal\Component\Utility\Xss as CoreXss; +use Drupal\Component\Utility\Xss; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface; @@ -670,7 +670,7 @@ public function renderItems($items) { if (!empty($items)) { $items = $this->prepareItemsByDelta($items); if ($this->options['multi_type'] == 'separator' || !$this->options['group_rows']) { - $separator = $this->options['multi_type'] == 'separator' ? CoreXss::filterAdmin($this->options['separator']) : ''; + $separator = $this->options['multi_type'] == 'separator' ? Xss::filterAdmin($this->options['separator']) : ''; $build = [ '#type' => 'inline_template', '#template' => '{{ items | safe_join(separator) }}', @@ -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)); } } @@ -915,17 +915,28 @@ protected function addSelfTokens(&$tokens, $item) { // 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); - } - if (isset($raw) && 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 . ' }}'] = ''; + $raw = $item['raw']; + + if (is_array($raw)) { + if (isset($raw[$id]) && is_scalar($raw[$id])) { + $tokens['{{ ' . $this->options['id'] . '__' . $id . ' }}'] = Xss::filterAdmin($raw[$id]); + } + else { + // Make sure that empty values are replaced as well. + $tokens['{{ ' . $this->options['id'] . '__' . $id . ' }}'] = ''; + } + } + + if (is_object($raw)) { + $property = $raw->get($id); + if (!empty($property)) { + $tokens['{{ ' . $this->options['id'] . '__' . $id . ' }}'] = Xss::filterAdmin($property->getValue()); + } + else { + // Make sure that empty values are replaced as well. + $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) { }