You are here

public function PageAccessCheck::access in Page Manager 8

Same name and namespace in other branches
  1. 8.4 src/Entity/PageAccessCheck.php \Drupal\page_manager\Entity\PageAccessCheck::access()

Checks access to the entity operation on the given route.

The route's '_entity_access' requirement must follow the pattern 'entity_stub_name.operation', where available operations are: 'view', 'update', 'create', and 'delete'.

For example, this route configuration invokes a permissions check for 'update' access to entities of type 'node':


pattern: '/foo/{node}/bar'
requirements:
  _entity_access: 'node.update'

And this will check 'delete' access to a dynamic entity type:


example.route:
  path: foo/{entity_type}/{example}
  requirements:
    _entity_access: example.delete
  options:
    parameters:
      example:
        type: entity:{entity_type}

The route match parameter corresponding to the stub name is checked to see if it is entity-like i.e. implements EntityInterface.

Parameters

\Symfony\Component\Routing\Route $route: The route to check against.

\Drupal\Core\Routing\RouteMatchInterface $route_match: The parametrized route

\Drupal\Core\Session\AccountInterface $account: The currently logged in account.

Return value

\Drupal\Core\Access\AccessResultInterface The access result.

Overrides EntityAccessCheck::access

See also

\Drupal\Core\ParamConverter\EntityConverter

File

src/Entity/PageAccessCheck.php, line 23
Contains \Drupal\page_manager\Entity\PageAccessCheck.

Class

PageAccessCheck
Mimics the generic entity access but with a custom key to prevent collisions.

Namespace

Drupal\page_manager\Entity

Code

public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account) {

  // Backup the original requirements.
  $original_requirements = $route
    ->getRequirements();

  // Replace it with our entity access value and run the parent access check.
  $route
    ->setRequirement('_entity_access', $route
    ->getRequirement('_page_access'));
  $access = parent::access($route, $route_match, $account);

  // Restore the original requirements.
  $route
    ->setRequirements($original_requirements);
  return $access;
}