3 namespace Drupal\layout_builder\Access;
5 use Drupal\Core\Access\AccessResult;
6 use Drupal\Core\Routing\Access\AccessInterface;
7 use Drupal\Core\Routing\RouteMatchInterface;
8 use Drupal\Core\Session\AccountInterface;
9 use Drupal\layout_builder\SectionStorageInterface;
12 * Provides an access check for the Layout Builder UI.
16 class LayoutSectionAccessCheck implements AccessInterface {
19 * Checks routing access to the layout.
21 * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
22 * The current route match.
23 * @param \Drupal\Core\Session\AccountInterface $account
24 * The currently logged in account.
26 * @return \Drupal\Core\Access\AccessResultInterface
29 public function access(RouteMatchInterface $route_match, AccountInterface $account) {
30 $section_storage = $route_match->getParameter('section_storage');
32 if (empty($section_storage)) {
33 return AccessResult::forbidden()->addCacheContexts(['route']);
36 if (!$section_storage instanceof SectionStorageInterface) {
37 $access = AccessResult::forbidden();
40 $access = AccessResult::allowedIfHasPermission($account, 'configure any layout');
43 return $access->addCacheableDependency($section_storage);