Mercurial > hg > isophonics-drupal-site
annotate core/modules/layout_builder/src/Access/LayoutSectionAccessCheck.php @ 15:e200cb7efeb3
Update Drupal core to 8.5.3 via Composer
author | Chris Cannam |
---|---|
date | Thu, 26 Apr 2018 11:26:54 +0100 |
parents | 1fec387a4317 |
children | af1871eacc83 |
rev | line source |
---|---|
Chris@14 | 1 <?php |
Chris@14 | 2 |
Chris@14 | 3 namespace Drupal\layout_builder\Access; |
Chris@14 | 4 |
Chris@14 | 5 use Drupal\Core\Access\AccessResult; |
Chris@14 | 6 use Drupal\Core\Routing\Access\AccessInterface; |
Chris@14 | 7 use Drupal\Core\Routing\RouteMatchInterface; |
Chris@14 | 8 use Drupal\Core\Session\AccountInterface; |
Chris@14 | 9 use Drupal\layout_builder\SectionStorageInterface; |
Chris@14 | 10 |
Chris@14 | 11 /** |
Chris@14 | 12 * Provides an access check for the Layout Builder UI. |
Chris@14 | 13 * |
Chris@14 | 14 * @internal |
Chris@14 | 15 */ |
Chris@14 | 16 class LayoutSectionAccessCheck implements AccessInterface { |
Chris@14 | 17 |
Chris@14 | 18 /** |
Chris@14 | 19 * Checks routing access to the layout. |
Chris@14 | 20 * |
Chris@14 | 21 * @param \Drupal\Core\Routing\RouteMatchInterface $route_match |
Chris@14 | 22 * The current route match. |
Chris@14 | 23 * @param \Drupal\Core\Session\AccountInterface $account |
Chris@14 | 24 * The currently logged in account. |
Chris@14 | 25 * |
Chris@14 | 26 * @return \Drupal\Core\Access\AccessResultInterface |
Chris@14 | 27 * The access result. |
Chris@14 | 28 */ |
Chris@14 | 29 public function access(RouteMatchInterface $route_match, AccountInterface $account) { |
Chris@14 | 30 $section_storage = $route_match->getParameter('section_storage'); |
Chris@14 | 31 |
Chris@14 | 32 if (empty($section_storage)) { |
Chris@14 | 33 return AccessResult::forbidden()->addCacheContexts(['route']); |
Chris@14 | 34 } |
Chris@14 | 35 |
Chris@14 | 36 if (!$section_storage instanceof SectionStorageInterface) { |
Chris@14 | 37 $access = AccessResult::forbidden(); |
Chris@14 | 38 } |
Chris@14 | 39 else { |
Chris@14 | 40 $access = AccessResult::allowedIfHasPermission($account, 'configure any layout'); |
Chris@14 | 41 } |
Chris@14 | 42 |
Chris@14 | 43 return $access->addCacheableDependency($section_storage); |
Chris@14 | 44 } |
Chris@14 | 45 |
Chris@14 | 46 } |