Newer
Older
Tim Plunkett
committed
namespace Drupal\node\Plugin\views\argument;
use Drupal\Core\Entity\EntityStorageInterface;
Alex Pott
committed
use Drupal\views\Plugin\views\argument\StringArgument;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Argument handler to accept a node type.
* @ViewsArgument("node_type")
Alex Pott
committed
class Type extends StringArgument {
/**
* NodeType storage handler.
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $nodeTypeStorage;
/**
* Constructs a new Node Type object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
* The entity storage class.
*/
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;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$entity_manager = $container->get('entity.manager');
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$entity_manager->getStorage('node_type')
);
}
Alex Pott
committed
* Override the behavior of summaryName(). Get the user friendly version
* of the node type.
*/
Alex Pott
committed
public function summaryName($data) {
return $this->node_type($data->{$this->name_alias});
}
/**
* Override the behavior of title(). Get the user friendly version of the
* node type.
*/
function title() {
return $this->node_type($this->argument);
}
function node_type($type_name) {
$type = $this->nodeTypeStorage->load($type_name);
$output = $type ? $type->label() : $this->t('Unknown content type');
return $output;