/** * Override the behavior of title(). Get the name of the vocabulary. */ function title() { $vocabulary = $this->vocabularyStorage->load($this->argument); if ($vocabulary) { return $vocabulary->label(); } return $this->t('No vocabulary'); }
/** * Override the behavior of title(). Get the name of the vocabulary. */ function title() { $vocabulary = $this->vocabularyStorage->load($this->argument); if ($vocabulary) { return SafeMarkup::checkPlain($vocabulary->label()); } return $this->t('No vocabulary'); }
/** * {@inheritdoc} */ public function massageFormValues(array $values, array $form, FormStateInterface $form_state) { // Autocomplete widgets do not send their tids in the form, so we must detect // them here and process them independently. $items = array(); // Collect candidate vocabularies. foreach ($this->getFieldSetting('allowed_values') as $tree) { if ($vocabulary = $this->vocabularyStorage->load($tree['vocabulary'])) { $vocabularies[$vocabulary->id()] = $vocabulary; } } // Translate term names into actual terms. foreach ($values as $value) { // See if the term exists in the chosen vocabulary and return the tid; // otherwise, create a new term. if ($possibilities = entity_load_multiple_by_properties('taxonomy_term', array('name' => trim($value), 'vid' => array_keys($vocabularies)))) { $term = array_pop($possibilities); $item = array('target_id' => $term->id()); } else { $vocabulary = reset($vocabularies); $term = entity_create('taxonomy_term', array('vid' => $vocabulary->id(), 'name' => $value)); $item = array('entity' => $term); } $items[] = $item; } return $items; }
/** * {@inheritdoc} */ public function calculateDependencies() { $dependencies = parent::calculateDependencies(); $vocabulary = $this->vocabularyStorage->load($this->options['vid']); $dependencies[$vocabulary->getConfigDependencyKey()][] = $vocabulary->getConfigDependencyName(); foreach ($this->termStorage->loadMultiple($this->options['value']) as $term) { $dependencies[$term->getConfigDependencyKey()][] = $term->getConfigDependencyName(); } return $dependencies; }
/** * {@inheritdoc} */ public function calculateDependencies() { $dependencies = parent::calculateDependencies(); foreach ($this->options['vids'] as $vocabulary_id) { if ($vocabulary = $this->vocabularyStorage->load($vocabulary_id)) { $dependencies[$vocabulary->getConfigDependencyKey()][] = $vocabulary->getConfigDependencyName(); } } return $dependencies; }
public function getOptions(FieldDefinitionInterface $field, $component) { $fs = $field->getFieldStorageDefinition()->getSettings(); $options = $fs[$component . '_options']; foreach ($options as $index => $opt) { if (preg_match('/^\\[vocabulary:([0-9a-z\\_]{1,})\\]/', trim($opt), $matches)) { unset($options[$index]); if ($this->termStorage && $this->vocabularyStorage) { $vocabulary = $this->vocabularyStorage->load($matches[1]); if ($vocabulary) { $max_length = isset($fs['max_length'][$component]) ? $fs['max_length'][$component] : 255; foreach ($this->termStorage->loadTree($vocabulary->id()) as $term) { if (Unicode::strlen($term->name) <= $max_length) { $options[] = $term->name; } } } } } } // Options could come from multiple sources, filter duplicates. $options = array_unique($options); if (isset($fs['sort_options']) && !empty($fs['sort_options'][$component])) { natcasesort($options); } $default = FALSE; foreach ($options as $index => $opt) { if (strpos($opt, '--') === 0) { unset($options[$index]); $default = trim(Unicode::substr($opt, 2)); } } $options = array_map('trim', $options); $options = array_combine($options, $options); if ($default !== FALSE) { $options = array('' => $default) + $options; } return $options; }
/** * Returns forum index page. * * @return array * A render array. */ public function forumIndex() { $vocabulary = $this->vocabularyStorage->load($this->config('forum.settings')->get('vocabulary')); $index = $this->forumManager->getIndex(); $build = $this->build($index->forums, $index); if (empty($index->forums)) { // Root of empty forum. $build['#title'] = $this->t('No forums defined'); } else { // Set the page title to forum's vocabulary name. $build['#title'] = $vocabulary->label(); } return $build; }
/** * Determines if the rdf type already exists. * * @param string $rid * The rdf type ID. * * @return bool * TRUE if the vocabulary exists, FALSE otherwise. */ public function exists($rid) { $action = $this->rdfTypeStorage->load($rid); return !empty($action); }