class VocabularyVid

Same name and namespace in other branches
  1. 11.x core/modules/taxonomy/src/Plugin/views/argument/VocabularyVid.php \Drupal\taxonomy\Plugin\views\argument\VocabularyVid

Argument handler to accept a vocabulary id.

Plugin annotation

@ViewsArgument("vocabulary_vid");

Hierarchy

Expanded class hierarchy of VocabularyVid

Related topics

File

core/modules/taxonomy/src/Plugin/views/argument/VocabularyVid.php, line 16

Namespace

Drupal\taxonomy\Plugin\views\argument
View source
class VocabularyVid extends NumericArgument {
  
  /**
   * The vocabulary storage.
   *
   * @var \Drupal\taxonomy\VocabularyStorageInterface
   */
  protected $vocabularyStorage;
  
  /**
   * Constructs the VocabularyVid object.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\taxonomy\VocabularyStorageInterface $vocabulary_storage
   *   The vocabulary storage.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, VocabularyStorageInterface $vocabulary_storage) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->vocabularyStorage = $vocabulary_storage;
  }
  
  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container->get('entity_type.manager')
      ->getStorage('taxonomy_vocabulary'));
  }
  
  /**
   * Override the behavior of title(). Get the name of the vocabulary.
   */
  public function title() {
    $vocabulary = $this->vocabularyStorage
      ->load($this->argument);
    if ($vocabulary) {
      return $vocabulary->label();
    }
    return $this->t('No vocabulary');
  }

}

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