You are here

public function TaxonomyIndexTid::preRender in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/taxonomy/src/Plugin/views/field/TaxonomyIndexTid.php \Drupal\taxonomy\Plugin\views\field\TaxonomyIndexTid::preRender()

Runs before any fields are rendered.

This gives the handlers some time to set up before any handler has been rendered.

Parameters

\Drupal\views\ResultRow[] $values: An array of all ResultRow objects returned from the query.

Overrides FieldPluginBase::preRender

File

core/modules/taxonomy/src/Plugin/views/field/TaxonomyIndexTid.php, line 132
Contains \Drupal\taxonomy\Plugin\views\field\TaxonomyIndexTid.

Class

TaxonomyIndexTid
Field handler to display all taxonomy terms of a node.

Namespace

Drupal\taxonomy\Plugin\views\field

Code

public function preRender(&$values) {
  $vocabularies = $this->vocabularyStorage
    ->loadMultiple();
  $this->field_alias = $this->aliases['nid'];
  $nids = array();
  foreach ($values as $result) {
    if (!empty($result->{$this->aliases['nid']})) {
      $nids[] = $result->{$this->aliases['nid']};
    }
  }
  if ($nids) {
    $vocabs = array_filter($this->options['vids']);
    if (empty($this->options['limit'])) {
      $vocabs = array();
    }
    $result = \Drupal::entityManager()
      ->getStorage('taxonomy_term')
      ->getNodeTerms($nids, $vocabs);
    foreach ($result as $node_nid => $data) {
      foreach ($data as $tid => $term) {
        $this->items[$node_nid][$tid]['name'] = \Drupal::entityManager()
          ->getTranslationFromContext($term)
          ->label();
        $this->items[$node_nid][$tid]['tid'] = $tid;
        $this->items[$node_nid][$tid]['vocabulary_vid'] = $term
          ->getVocabularyId();
        $this->items[$node_nid][$tid]['vocabulary'] = $vocabularies[$term
          ->getVocabularyId()]
          ->label();
        if (!empty($this->options['link_to_taxonomy'])) {
          $this->items[$node_nid][$tid]['make_link'] = TRUE;
          $this->items[$node_nid][$tid]['path'] = 'taxonomy/term/' . $tid;
        }
      }
    }
  }
}