3 namespace Drupal\ctools\Access;
6 use Drupal\Core\Access\AccessResult;
7 use Drupal\Core\Routing\Access\AccessInterface as CoreAccessInterface;
8 use Drupal\Core\Routing\RouteMatch;
9 use Drupal\Core\Session\AccountInterface;
10 use Drupal\ctools\Access\AccessInterface as CToolsAccessInterface;
11 use Drupal\user\SharedTempStoreFactory;
12 use Symfony\Component\Routing\Route;
14 class TempstoreAccess implements CoreAccessInterface {
17 * The shared tempstore factory.
19 * @var \Drupal\user\SharedTempStoreFactory
23 public function __construct(SharedTempStoreFactory $tempstore) {
24 $this->tempstore = $tempstore;
27 protected function getTempstore() {
28 return $this->tempstore;
31 public function access(Route $route, RouteMatch $match, AccountInterface $account) {
32 $tempstore_id = $match->getParameter('tempstore_id') ? $match->getParameter('tempstore_id') : $route->getDefault('tempstore_id');
33 $id = $match->getParameter($route->getRequirement('_ctools_access'));
34 if ($tempstore_id && $id) {
35 $cached_values = $this->getTempstore()->get($tempstore_id)->get($id);
36 if (!empty($cached_values['access']) && ($cached_values['access'] instanceof CToolsAccessInterface)) {
37 $access = $cached_values['access']->access($account);
40 $access = AccessResult::allowed();
44 $access = AccessResult::forbidden();
46 // The different wizards will have different tempstore ids and adding this
47 // cache context allows us to nuance the access per wizard.
48 $access->addCacheContexts(['url.query_args:tempstore_id']);