diff --git a/core/modules/views/src/Plugin/views/field/Field.php b/core/modules/views/src/Plugin/views/field/Field.php index 4192719..474c80b 100644 --- a/core/modules/views/src/Plugin/views/field/Field.php +++ b/core/modules/views/src/Plugin/views/field/Field.php @@ -8,7 +8,7 @@ namespace Drupal\views\Plugin\views\field; use Drupal\Component\Utility\SafeMarkup; -use Drupal\Component\Utility\Xss as CoreXss; +use Drupal\Component\Utility\Xss; use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityManagerInterface; @@ -902,8 +902,9 @@ function render_item($count, $item) { protected function documentSelfTokens(&$tokens) { $field = $this->getFieldDefinition(); + dsm($field->getColumns(), 'columns'); 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 +916,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 . ' }}'] = ''; + } + } } } }