class AccessCheck

Same name in other branches
  1. 9 core/modules/system/tests/modules/menu_test/src/Access/AccessCheck.php \Drupal\menu_test\Access\AccessCheck
  2. 8.9.x core/modules/system/tests/modules/menu_test/src/Access/AccessCheck.php \Drupal\menu_test\Access\AccessCheck
  3. 11.x core/modules/system/tests/modules/menu_test/src/Access/AccessCheck.php \Drupal\menu_test\Access\AccessCheck

Checks access based on the 'menu_test' key in session.

Hierarchy

Expanded class hierarchy of AccessCheck

1 string reference to 'AccessCheck'
menu_test.services.yml in core/modules/system/tests/modules/menu_test/menu_test.services.yml
core/modules/system/tests/modules/menu_test/menu_test.services.yml
1 service uses AccessCheck
access_check.menu_test_session in core/modules/system/tests/modules/menu_test/menu_test.services.yml
Drupal\menu_test\Access\AccessCheck

File

core/modules/system/tests/modules/menu_test/src/Access/AccessCheck.php, line 14

Namespace

Drupal\menu_test\Access
View source
class AccessCheck implements AccessInterface, ContainerInjectionInterface {
    
    /**
     * The request stack.
     *
     * @var \Symfony\Component\HttpFoundation\RequestStack
     */
    protected $requestStack;
    
    /**
     * Constructs a new AccessCheck class.
     *
     * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
     *   The request stack.
     */
    public function __construct(RequestStack $request_stack) {
        $this->requestStack = $request_stack;
    }
    
    /**
     * {@inheritdoc}
     */
    public static function create(ContainerInterface $container) {
        return new static($container->get('request_stack'));
    }
    
    /**
     * Check to see if user accessed this page.
     *
     * @return \Drupal\Core\Access\AccessResultInterface
     *   The access result.
     */
    public function access() {
        $result = AccessResult::allowedIf($this->requestStack
            ->getCurrentRequest()
            ->getSession()
            ->get('menu_test', 0) < 2);
        return $result->setCacheMaxAge(0);
    }
    
    /**
     * @return \Drupal\Core\Access\AccessResultForbidden
     */
    public function menuLocalAction7() {
        return AccessResult::forbidden()->addCacheTags([
            'menu_local_action7',
        ])
            ->addCacheContexts([
            'url.query_args:menu_local_action7',
        ]);
    }
    
    /**
     * @return \Drupal\Core\Access\AccessResultAllowed
     */
    public function menuLocalAction8() {
        return AccessResult::allowed()->addCacheTags([
            'menu_local_action8',
        ])
            ->addCacheContexts([
            'url.query_args:menu_local_action8',
        ]);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
AccessCheck::$requestStack protected property The request stack.
AccessCheck::access public function Check to see if user accessed this page.
AccessCheck::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
AccessCheck::menuLocalAction7 public function
AccessCheck::menuLocalAction8 public function
AccessCheck::__construct public function Constructs a new AccessCheck class.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.