commerce_gc_client-8.x-1.9/src/Controller/RecurrenceRules.php
src/Controller/RecurrenceRules.php
<?php
/**
* @file
* Contains \Drupal\commerce_gc_client\Controller\RecurrenceRules.
*/
namespace Drupal\commerce_gc_client\Controller;
use Drupal\commerce_gc_client\RecurrenceRulesPluginManager;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Controller for product variation Recurrence Rules form.
*/
class RecurrenceRules extends ControllerBase {
/**
* The Recurrence Rules Plugin Manager.
*
* @var \Drupal\commerce_gc_client\RecurrenceRulesPluginManager
*/
protected $pluginManager;
/**
* The route match interface.
*
* @var \Drupal\Core\Routing\RouteMatchInterface
*/
protected $routeMatch;
/**
* The commerce_gc_client.settings config object.
*/
protected $config;
/**
* Constructs the Recurrence Rules object.
*
* @param \Drupal\commerce_gc_client\RecurrenceRulesPluginManager $plugin_manager
* The Recurrence Rules plugin manager.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The Route match interface.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory interface.
*/
public function __construct(RecurrenceRulesPluginManager $plugin_manager, RouteMatchInterface $route_match, ConfigFactoryInterface $config_factory) {
$this->pluginManager = $plugin_manager;
$this->routeMatch = $route_match;
$this->config = $config_factory->get('commerce_gc_client.settings');
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('plugin.manager.commerce_gc_client.recurrence_rules'),
$container->get('current_route_match'),
$container->get('config.factory'),
);
}
/**
* Redirects user to the GoCardless payment gateway settings page.
*/
public function update($commerce_product = NULL, $commerce_product_variation = NULL) {
return $this->pluginManager->createInstance('standard')->buildForm($commerce_product_variation);
}
/**
* Controls access to the page.
*
* @param \Drupal\Core\Session\AccountInterface $account
* Run access checks for this account.
*
* @return \Drupal\Core\Access\AccessResult
* The access result.
*/
public function access(AccountInterface $account) {
$result = AccessResult::forbidden();
if ($variation = $this->routeMatch->getParameter('commerce_product_variation')) {
$gc_variation_types = $this->config->get('product_variation_types');
if (in_array($variation->bundle(), $gc_variation_types)) {
$result = AccessResult::allowed();
}
}
return $result;
}
}