Vid.php in Drupal 9
File
core/modules/node/src/Plugin/views/argument/Vid.php
View source
<?php
namespace Drupal\node\Plugin\views\argument;
use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
use Drupal\views\Plugin\views\argument\NumericArgument;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\node\NodeStorageInterface;
class Vid extends NumericArgument {
use DeprecatedServicePropertyTrait;
protected $deprecatedProperties = [
'database' => 'database',
];
protected $nodeStorage;
public function __construct(array $configuration, $plugin_id, $plugin_definition, $node_storage) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
if (!$node_storage instanceof NodeStorageInterface) {
@trigger_error('Passing the database service to ' . __METHOD__ . '() is deprecated in drupal:9.2.0 and will be removed before drupal:10.0.0. See https://www.drupal.org/node/3178412', E_USER_DEPRECATED);
$node_storage = func_get_arg(4);
}
if (!$node_storage instanceof NodeStorageInterface) {
throw new \InvalidArgumentException('The fourth argument must implement \\Drupal\\node\\NodeStorageInterface.');
}
$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 = [];
$results = $this->nodeStorage
->getAggregateQuery()
->accessCheck(FALSE)
->allRevisions()
->groupBy('title')
->execute();
foreach ($results as $result) {
$titles[] = $result['title'];
}
return $titles;
}
}
Classes
Name |
Description |
Vid |
Argument handler to accept a node revision id. |