commerce_product_bundles-8.x-1.0/src/Plugin/views/argument_default/ProductBundleVariation.php
src/Plugin/views/argument_default/ProductBundleVariation.php
<?php namespace Drupal\commerce_product_bundles\Plugin\views\argument_default; use Drupal\commerce_product_bundles\Entity\ProductBundleVariationInterface; 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; /** * Default argument plugin to extract a product bundle variation. * * Code was taken form and modified: * @see \Drupal\commerce_product\Plugin\views\argument_default\ProductVariation * * @ViewsArgumentDefault( * id = "product_bundle_variation", * title = @Translation("Product Bundle variation ID from URL") * ) */ class ProductBundleVariation extends ArgumentDefaultPluginBase implements CacheableDependencyInterface { /** * The route match. * * @var \Drupal\Core\Routing\RouteMatchInterface */ protected $routeMatch; /** * ProductBundleVariation constructor. * * @param array $configuration * @param $plugin_id * @param $plugin_definition * @param \Drupal\Core\Routing\RouteMatchInterface $route_match */ public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteMatchInterface $route_match) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->routeMatch = $route_match; } /** * {@inheritdoc} */ 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') ); } /** * {@inheritdoc} */ public function getArgument() { if (($bundle_variation = $this->routeMatch->getParameter('commerce_bundle_variation')) && $bundle_variation instanceof ProductBundleVariationInterface) { return $bundle_variation->id(); } } /** * {@inheritdoc} */ public function getCacheMaxAge() { return Cache::PERMANENT; } /** * {@inheritdoc} */ public function getCacheContexts() { return ['url']; } }