Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / taxonomy / src / Plugin / views / argument / Taxonomy.php
1 <?php
2
3 namespace Drupal\taxonomy\Plugin\views\argument;
4
5 use Drupal\Core\Entity\EntityStorageInterface;
6 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
7 use Drupal\views\Plugin\views\argument\NumericArgument;
8 use Symfony\Component\DependencyInjection\ContainerInterface;
9
10 /**
11  * Argument handler for basic taxonomy tid.
12  *
13  * @ingroup views_argument_handlers
14  *
15  * @ViewsArgument("taxonomy")
16  */
17 class Taxonomy extends NumericArgument implements ContainerFactoryPluginInterface {
18
19   /**
20    * @var \Drupal\Core\Entity\EntityStorageInterface
21    */
22   protected $termStorage;
23
24   /**
25    * {@inheritdoc}
26    */
27   public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityStorageInterface $term_storage) {
28     parent::__construct($configuration, $plugin_id, $plugin_definition);
29
30     $this->termStorage = $term_storage;
31   }
32
33   /**
34    * {@inheritdoc}
35    */
36   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
37     return new static(
38       $configuration,
39       $plugin_id,
40       $plugin_definition,
41       $container->get('entity.manager')->getStorage('taxonomy_term')
42     );
43   }
44
45   /**
46    * Override the behavior of title(). Get the title of the node.
47    */
48   public function title() {
49     // There might be no valid argument.
50     if ($this->argument) {
51       $term = $this->termStorage->load($this->argument);
52       if (!empty($term)) {
53         return $term->getName();
54       }
55     }
56     // TODO review text
57     return $this->t('No name');
58   }
59
60 }