3 namespace Drupal\node\Plugin\views\argument;
5 use Drupal\Core\Entity\EntityStorageInterface;
6 use Drupal\views\Plugin\views\argument\StringArgument;
7 use Symfony\Component\DependencyInjection\ContainerInterface;
10 * Argument handler to accept a node type.
12 * @ViewsArgument("node_type")
14 class Type extends StringArgument {
17 * NodeType storage handler.
19 * @var \Drupal\Core\Entity\EntityStorageInterface
21 protected $nodeTypeStorage;
24 * Constructs a new Node Type object.
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.
35 public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityStorageInterface $node_type_storage) {
36 parent::__construct($configuration, $plugin_id, $plugin_definition);
38 $this->nodeTypeStorage = $node_type_storage;
44 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
45 $entity_manager = $container->get('entity.manager');
50 $entity_manager->getStorage('node_type')
55 * Override the behavior of summaryName(). Get the user friendly version
58 public function summaryName($data) {
59 return $this->node_type($data->{$this->name_alias});
63 * Override the behavior of title(). Get the user friendly version of the
66 public function title() {
67 return $this->node_type($this->argument);
70 public function node_type($type_name) {
71 $type = $this->nodeTypeStorage->load($type_name);
72 $output = $type ? $type->label() : $this->t('Unknown content type');