You are here

public function TermName::getItems in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/taxonomy/src/Plugin/views/field/TermName.php \Drupal\taxonomy\Plugin\views\field\TermName::getItems()
  2. 9 core/modules/taxonomy/src/Plugin/views/field/TermName.php \Drupal\taxonomy\Plugin\views\field\TermName::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 = $item['raw']
        ->get('value')
        ->getValue();

      // @todo Add link support https://www.drupal.org/node/2567745
      $item['rendered']['#context']['value'] = str_replace(' ', '-', $name);
    }
  }
  return $items;
}