"Fossies" - the Fresh Open Source Software Archive

Member "drupal-8.9.10/core/modules/node/src/Plugin/views/argument_default/Node.php" (26 Nov 2020, 2057 Bytes) of package /linux/www/drupal-8.9.10.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 <?php
    2 
    3 namespace Drupal\node\Plugin\views\argument_default;
    4 
    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;
   11 
   12 /**
   13  * Default argument plugin to extract a node.
   14  *
   15  * @ViewsArgumentDefault(
   16  *   id = "node",
   17  *   title = @Translation("Content ID from URL")
   18  * )
   19  */
   20 class Node extends ArgumentDefaultPluginBase implements CacheableDependencyInterface {
   21 
   22   /**
   23    * The route match.
   24    *
   25    * @var \Drupal\Core\Routing\RouteMatchInterface
   26    */
   27   protected $routeMatch;
   28 
   29   /**
   30    * Constructs a new Node instance.
   31    *
   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
   39    *   The route match.
   40    */
   41   public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteMatchInterface $route_match) {
   42     parent::__construct($configuration, $plugin_id, $plugin_definition);
   43 
   44     $this->routeMatch = $route_match;
   45   }
   46 
   47   /**
   48    * {@inheritdoc}
   49    */
   50   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
   51     return new static(
   52       $configuration,
   53       $plugin_id,
   54       $plugin_definition,
   55       $container->get('current_route_match')
   56     );
   57   }
   58 
   59   /**
   60    * {@inheritdoc}
   61    */
   62   public function getArgument() {
   63     if (($node = $this->routeMatch->getParameter('node')) && $node instanceof NodeInterface) {
   64       return $node->id();
   65     }
   66   }
   67 
   68   /**
   69    * {@inheritdoc}
   70    */
   71   public function getCacheMaxAge() {
   72     return Cache::PERMANENT;
   73   }
   74 
   75   /**
   76    * {@inheritdoc}
   77    */
   78   public function getCacheContexts() {
   79     return ['url'];
   80   }
   81 
   82 }