3 namespace Drupal\node\Plugin\views\argument_default;
5 use Drupal\Core\Cache\Cache;
6 use Drupal\Core\Cache\CacheableDependencyInterface;
7 use Drupal\Core\Routing\RouteMatchInterface;
8 use Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase;
9 use Drupal\node\NodeInterface;
10 use Symfony\Component\DependencyInjection\ContainerInterface;
13 * Default argument plugin to extract a node.
15 * @ViewsArgumentDefault(
17 * title = @Translation("Content ID from URL")
20 class Node extends ArgumentDefaultPluginBase implements CacheableDependencyInterface {
25 * @var \Drupal\Core\Routing\RouteMatchInterface
27 protected $routeMatch;
30 * Constructs a new Node instance.
32 * @param array $configuration
33 * A configuration array containing information about the plugin instance.
34 * @param string $plugin_id
35 * The plugin_id for the plugin instance.
36 * @param mixed $plugin_definition
37 * The plugin implementation definition.
38 * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
41 public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteMatchInterface $route_match) {
42 parent::__construct($configuration, $plugin_id, $plugin_definition);
44 $this->routeMatch = $route_match;
50 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
55 $container->get('current_route_match')
62 public function getArgument() {
63 if (($node = $this->routeMatch->getParameter('node')) && $node instanceof NodeInterface) {
71 public function getCacheMaxAge() {
72 return Cache::PERMANENT;
78 public function getCacheContexts() {