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; } } } } }
/** * {@inheritdoc} */ public function calculateDependencies() { $dependencies = parent::calculateDependencies(); foreach ($this->vocabularyStorage->loadMultiple(array_keys($this->options['vids'])) as $vocabulary) { $dependencies[$vocabulary->getConfigDependencyKey()][] = $vocabulary->getConfigDependencyName(); } return $dependencies; }
/** * Determines if the vocabulary already exists. * * @param string $vid * The vocabulary ID. * * @return bool * TRUE if the vocabulary exists, FALSE otherwise. */ public function exists($vid) { $action = $this->vocabularyStorage->load($vid); return !empty($action); }