Product.php in Commerce Core 8.2
File
modules/product/src/Plugin/views/argument_default/Product.php
View source
<?php
namespace Drupal\commerce_product\Plugin\views\argument_default;
use Drupal\commerce_product\Entity\ProductInterface;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
class Product 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 (($product = $this->routeMatch
->getParameter('commerce_product')) && $product instanceof ProductInterface) {
return $product
->id();
}
}
public function getCacheMaxAge() {
return Cache::PERMANENT;
}
public function getCacheContexts() {
return [
'url',
];
}
}
Classes
Name |
Description |
Product |
Default argument plugin to extract a product. |