Pull merge.
[yaffs-website] / web / core / modules / layout_builder / src / Access / LayoutSectionAccessCheck.php
1 <?php
2
3 namespace Drupal\layout_builder\Access;
4
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;
10
11 /**
12  * Provides an access check for the Layout Builder UI.
13  *
14  * @internal
15  */
16 class LayoutSectionAccessCheck implements AccessInterface {
17
18   /**
19    * Checks routing access to the layout.
20    *
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.
25    *
26    * @return \Drupal\Core\Access\AccessResultInterface
27    *   The access result.
28    */
29   public function access(RouteMatchInterface $route_match, AccountInterface $account) {
30     $section_storage = $route_match->getParameter('section_storage');
31
32     if (empty($section_storage)) {
33       return AccessResult::forbidden()->addCacheContexts(['route']);
34     }
35
36     if (!$section_storage instanceof SectionStorageInterface) {
37       $access = AccessResult::forbidden();
38     }
39     else {
40       $access = AccessResult::allowedIfHasPermission($account, 'configure any layout');
41     }
42
43     return $access->addCacheableDependency($section_storage);
44   }
45
46 }