You are here

public function LayoutBuilderAccessCheck::access in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/layout_builder/src/Access/LayoutBuilderAccessCheck.php \Drupal\layout_builder\Access\LayoutBuilderAccessCheck::access()
  2. 9 core/modules/layout_builder/src/Access/LayoutBuilderAccessCheck.php \Drupal\layout_builder\Access\LayoutBuilderAccessCheck::access()

Checks routing access to the layout.

Parameters

\Drupal\layout_builder\SectionStorageInterface $section_storage: The section storage.

\Drupal\Core\Session\AccountInterface $account: The current user.

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

Return value

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

File

core/modules/layout_builder/src/Access/LayoutBuilderAccessCheck.php, line 35

Class

LayoutBuilderAccessCheck
Provides an access check for the Layout Builder defaults.

Namespace

Drupal\layout_builder\Access

Code

public function access(SectionStorageInterface $section_storage, AccountInterface $account, Route $route) {
  $operation = $route
    ->getRequirement('_layout_builder_access');
  $access = $section_storage
    ->access($operation, $account, TRUE);

  // Check for the global permission unless the section storage checks
  // permissions itself.
  if (!$section_storage
    ->getPluginDefinition()
    ->get('handles_permission_check')) {
    $access = $access
      ->andIf(AccessResult::allowedIfHasPermission($account, 'configure any layout'));
  }
  if ($access instanceof RefinableCacheableDependencyInterface) {
    $access
      ->addCacheableDependency($section_storage);
  }
  return $access;
}