Type.php in Drupal 8
File
core/modules/node/src/Plugin/views/argument/Type.php
View source
<?php
namespace Drupal\node\Plugin\views\argument;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\views\Plugin\views\argument\StringArgument;
use Symfony\Component\DependencyInjection\ContainerInterface;
class Type extends StringArgument {
protected $nodeTypeStorage;
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityStorageInterface $node_type_storage) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->nodeTypeStorage = $node_type_storage;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$entity_type_manager = $container
->get('entity_type.manager');
return new static($configuration, $plugin_id, $plugin_definition, $entity_type_manager
->getStorage('node_type'));
}
public function summaryName($data) {
return $this
->node_type($data->{$this->name_alias});
}
public function title() {
return $this
->node_type($this->argument);
}
public function node_type($type_name) {
$type = $this->nodeTypeStorage
->load($type_name);
$output = $type ? $type
->label() : $this
->t('Unknown content type');
return $output;
}
}
Classes
Name |
Description |
Type |
Argument handler to accept a node type. |