function TermName::getItems

Same name and namespace in other branches
  1. 9 core/modules/taxonomy/src/Plugin/views/field/TermName.php \Drupal\taxonomy\Plugin\views\field\TermName::getItems()
  2. 8.9.x core/modules/taxonomy/src/Plugin/views/field/TermName.php \Drupal\taxonomy\Plugin\views\field\TermName::getItems()
  3. 11.x core/modules/taxonomy/src/Plugin/views/field/TermName.php \Drupal\taxonomy\Plugin\views\field\TermName::getItems()

Gets an array of items for the field.

Parameters

\Drupal\views\ResultRow $values: The result row object containing the values.

Return value

array An array of items for the field.

Overrides EntityField::getItems

File

core/modules/taxonomy/src/Plugin/views/field/TermName.php, line 21

Class

TermName
Displays taxonomy term names and allows converting spaces to hyphens.

Namespace

Drupal\taxonomy\Plugin\views\field

Code

public function getItems(ResultRow $values) {
  $items = parent::getItems($values);
  if ($this->options['convert_spaces']) {
    foreach ($items as &$item) {
      // Replace spaces with hyphens.
      $name = str_replace(' ', '-', $item['raw']->get('value')
        ->getValue());
      empty($this->options['settings']['link_to_entity']) ? $item['rendered']['#context']['value'] = $name : ($item['rendered']['#title']['#context']['value'] = $name);
    }
  }
  return $items;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.