Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / node / src / Plugin / views / argument / Type.php
1 <?php
2
3 namespace Drupal\node\Plugin\views\argument;
4
5 use Drupal\Core\Entity\EntityStorageInterface;
6 use Drupal\views\Plugin\views\argument\StringArgument;
7 use Symfony\Component\DependencyInjection\ContainerInterface;
8
9 /**
10  * Argument handler to accept a node type.
11  *
12  * @ViewsArgument("node_type")
13  */
14 class Type extends StringArgument {
15
16   /**
17    * NodeType storage handler.
18    *
19    * @var \Drupal\Core\Entity\EntityStorageInterface
20    */
21   protected $nodeTypeStorage;
22
23   /**
24    * Constructs a new Node Type object.
25    *
26    * @param array $configuration
27    *   A configuration array containing information about the plugin instance.
28    * @param string $plugin_id
29    *   The plugin_id for the plugin instance.
30    * @param mixed $plugin_definition
31    *   The plugin implementation definition.
32    * @param \Drupal\Core\Entity\EntityStorageInterface $node_type_storage
33    *   The entity storage class.
34    */
35   public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityStorageInterface $node_type_storage) {
36     parent::__construct($configuration, $plugin_id, $plugin_definition);
37
38     $this->nodeTypeStorage = $node_type_storage;
39   }
40
41   /**
42    * {@inheritdoc}
43    */
44   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
45     $entity_manager = $container->get('entity.manager');
46     return new static(
47       $configuration,
48       $plugin_id,
49       $plugin_definition,
50       $entity_manager->getStorage('node_type')
51     );
52   }
53
54   /**
55    * Override the behavior of summaryName(). Get the user friendly version
56    * of the node type.
57    */
58   public function summaryName($data) {
59     return $this->node_type($data->{$this->name_alias});
60   }
61
62   /**
63    * Override the behavior of title(). Get the user friendly version of the
64    * node type.
65    */
66   public function title() {
67     return $this->node_type($this->argument);
68   }
69
70   public function node_type($type_name) {
71     $type = $this->nodeTypeStorage->load($type_name);
72     $output = $type ? $type->label() : $this->t('Unknown content type');
73     return $output;
74   }
75
76 }