ProductVariation.php in Commerce Core 8.2
File
modules/product/src/Plugin/views/argument_default/ProductVariation.php
View source
<?php
namespace Drupal\commerce_product\Plugin\views\argument_default;
use Drupal\commerce_product\Entity\ProductVariationInterface;
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 ProductVariation 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 (($variation = $this->routeMatch
->getParameter('commerce_product_variation')) && $variation instanceof ProductVariationInterface) {
return $variation
->id();
}
}
public function getCacheMaxAge() {
return Cache::PERMANENT;
}
public function getCacheContexts() {
return [
'url',
];
}
}