Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / taxonomy / src / Plugin / views / argument / VocabularyVid.php
1 <?php
2
3 namespace Drupal\taxonomy\Plugin\views\argument;
4
5 use Drupal\views\Plugin\views\argument\NumericArgument;
6 use Drupal\taxonomy\VocabularyStorageInterface;
7 use Symfony\Component\DependencyInjection\ContainerInterface;
8
9 /**
10  * Argument handler to accept a vocabulary id.
11  *
12  * @ingroup views_argument_handlers
13  *
14  * @ViewsArgument("vocabulary_vid")
15  */
16 class VocabularyVid extends NumericArgument {
17
18   /**
19     * The vocabulary storage.
20     *
21     * @var \Drupal\taxonomy\VocabularyStorageInterface
22     */
23   protected $vocabularyStorage;
24
25   /**
26    * Constructs the VocabularyVid object.
27    *
28    * @param array $configuration
29    *   A configuration array containing information about the plugin instance.
30    * @param string $plugin_id
31    *   The plugin_id for the plugin instance.
32    * @param mixed $plugin_definition
33    *   The plugin implementation definition.
34    * @param \Drupal\taxonomy\VocabularyStorageInterface $vocabulary_storage
35    *   The vocabulary storage.
36    */
37   public function __construct(array $configuration, $plugin_id, $plugin_definition, VocabularyStorageInterface $vocabulary_storage) {
38     parent::__construct($configuration, $plugin_id, $plugin_definition);
39     $this->vocabularyStorage = $vocabulary_storage;
40   }
41
42   /**
43    * {@inheritdoc}
44    */
45   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
46     return new static(
47       $configuration,
48       $plugin_id,
49       $plugin_definition,
50       $container->get('entity.manager')->getStorage('taxonomy_vocabulary')
51     );
52   }
53
54   /**
55    * Override the behavior of title(). Get the name of the vocabulary.
56    */
57   public function title() {
58     $vocabulary = $this->vocabularyStorage->load($this->argument);
59     if ($vocabulary) {
60       return $vocabulary->label();
61     }
62
63     return $this->t('No vocabulary');
64   }
65
66 }