annotate core/modules/layout_builder/src/Access/LayoutSectionAccessCheck.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents af1871eacc83
children
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@18 15 * Tagged services are internal.
Chris@18 16 *
Chris@18 17 * @todo Deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use
Chris@18 18 * \Drupal\layout_builder\Access\LayoutBuilderAccessCheck instead. See
Chris@18 19 * https://www.drupal.org/node/3039551.
Chris@14 20 */
Chris@14 21 class LayoutSectionAccessCheck implements AccessInterface {
Chris@14 22
Chris@14 23 /**
Chris@14 24 * Checks routing access to the layout.
Chris@14 25 *
Chris@14 26 * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
Chris@14 27 * The current route match.
Chris@14 28 * @param \Drupal\Core\Session\AccountInterface $account
Chris@14 29 * The currently logged in account.
Chris@14 30 *
Chris@14 31 * @return \Drupal\Core\Access\AccessResultInterface
Chris@14 32 * The access result.
Chris@14 33 */
Chris@14 34 public function access(RouteMatchInterface $route_match, AccountInterface $account) {
Chris@18 35 @trigger_error(__NAMESPACE__ . '\LayoutSectionAccessCheck is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal\layout_builder\Access\LayoutBuilderAccessCheck instead. See https://www.drupal.org/node/3039551.', E_USER_DEPRECATED);
Chris@14 36 $section_storage = $route_match->getParameter('section_storage');
Chris@14 37
Chris@14 38 if (empty($section_storage)) {
Chris@14 39 return AccessResult::forbidden()->addCacheContexts(['route']);
Chris@14 40 }
Chris@14 41
Chris@14 42 if (!$section_storage instanceof SectionStorageInterface) {
Chris@14 43 $access = AccessResult::forbidden();
Chris@14 44 }
Chris@14 45 else {
Chris@14 46 $access = AccessResult::allowedIfHasPermission($account, 'configure any layout');
Chris@14 47 }
Chris@14 48
Chris@14 49 return $access->addCacheableDependency($section_storage);
Chris@14 50 }
Chris@14 51
Chris@14 52 }