Node.php in Drupal 8
File
core/modules/node/src/Plugin/views/argument_default/Node.php
View source
<?php
namespace Drupal\node\Plugin\views\argument_default;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase;
use Drupal\node\NodeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class Node extends ArgumentDefaultPluginBase implements CacheableDependencyInterface {
protected $routeMatch;
public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteMatchInterface $route_match) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->routeMatch = $route_match;
}
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'));
}
public function getArgument() {
if (($node = $this->routeMatch
->getParameter('node')) && $node instanceof NodeInterface) {
return $node
->id();
}
}
public function getCacheMaxAge() {
return Cache::PERMANENT;
}
public function getCacheContexts() {
return [
'url',
];
}
}
Classes
Name |
Description |
Node |
Default argument plugin to extract a node. |