TopLevelBook.php in Drupal 9
File
core/modules/book/src/Plugin/views/argument_default/TopLevelBook.php
View source
<?php
namespace Drupal\book\Plugin\views\argument_default;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\node\NodeStorageInterface;
use Drupal\node\Plugin\views\argument_default\Node;
use Symfony\Component\DependencyInjection\ContainerInterface;
class TopLevelBook extends Node {
protected $nodeStorage;
public function __construct(array $configuration, $plugin_id, array $plugin_definition, RouteMatchInterface $route_match, NodeStorageInterface $node_storage) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $route_match);
$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('current_route_match'), $container
->get('entity_type.manager')
->getStorage('node'));
}
public function getArgument() {
$nid = parent::getArgument();
if (!empty($nid)) {
$node = $this->nodeStorage
->load($nid);
if (isset($node->book['bid'])) {
return $node->book['bid'];
}
}
}
}
Classes
Name |
Description |
TopLevelBook |
Default argument plugin to get the current node's top level book. |