You are here

class TopLevelBook in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/book/src/Plugin/views/argument_default/TopLevelBook.php \Drupal\book\Plugin\views\argument_default\TopLevelBook
  2. 9 core/modules/book/src/Plugin/views/argument_default/TopLevelBook.php \Drupal\book\Plugin\views\argument_default\TopLevelBook

Default argument plugin to get the current node's top level book.

Plugin annotation


@ViewsArgumentDefault(
  id = "top_level_book",
  title = @Translation("Top Level Book from current node")
)

Hierarchy

  • class \Drupal\node\Plugin\views\argument_default\Node extends \Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase implements CacheableDependencyInterface
    • class \Drupal\book\Plugin\views\argument_default\TopLevelBook

Expanded class hierarchy of TopLevelBook

File

core/modules/book/src/Plugin/views/argument_default/TopLevelBook.php, line 18

Namespace

Drupal\book\Plugin\views\argument_default
View source
class TopLevelBook extends Node {

  /**
   * The node storage controller.
   *
   * @var \Drupal\node\NodeStorageInterface
   */
  protected $nodeStorage;

  /**
   * Constructs a Drupal\book\Plugin\views\argument_default\TopLevelBook 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 array $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
   *   The route match.
   * @param \Drupal\node\NodeStorageInterface $node_storage
   *   The node storage controller.
   */
  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;
  }

  /**
   * {@inheritdoc}
   */
  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'));
  }

  /**
   * {@inheritdoc}
   */
  public function getArgument() {

    // Use the argument_default_node plugin to get the nid argument.
    $nid = parent::getArgument();
    if (!empty($nid)) {
      $node = $this->nodeStorage
        ->load($nid);
      if (isset($node->book['bid'])) {
        return $node->book['bid'];
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheableDependencyInterface::getCacheTags public function The cache tags associated with this object. 17
Node::$routeMatch protected property The route match.
Node::getCacheContexts public function The cache contexts associated with this object. Overrides CacheableDependencyInterface::getCacheContexts
Node::getCacheMaxAge public function The maximum age for which this object may be cached. Overrides CacheableDependencyInterface::getCacheMaxAge
TopLevelBook::$nodeStorage protected property The node storage controller.
TopLevelBook::create public static function Overrides Node::create
TopLevelBook::getArgument public function Overrides Node::getArgument
TopLevelBook::__construct public function Constructs a Drupal\book\Plugin\views\argument_default\TopLevelBook object. Overrides Node::__construct