Nid.php in Drupal 8
File
core/modules/node/src/Plugin/views/argument/Nid.php
View source
<?php
namespace Drupal\node\Plugin\views\argument;
use Drupal\node\NodeStorageInterface;
use Drupal\views\Plugin\views\argument\NumericArgument;
use Symfony\Component\DependencyInjection\ContainerInterface;
class Nid extends NumericArgument {
protected $nodeStorage;
public function __construct(array $configuration, $plugin_id, $plugin_definition, NodeStorageInterface $node_storage) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->nodeStorage = $node_storage;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_type.manager')
->getStorage('node'));
}
public function titleQuery() {
$titles = [];
$nodes = $this->nodeStorage
->loadMultiple($this->value);
foreach ($nodes as $node) {
$titles[] = $node
->label();
}
return $titles;
}
}
Classes
Name |
Description |
Nid |
Argument handler to accept a node id. |