annotate core/modules/layout_builder/src/Access/LayoutBuilderAccessCheck.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@17 1 <?php
Chris@17 2
Chris@17 3 namespace Drupal\layout_builder\Access;
Chris@17 4
Chris@18 5 use Drupal\Core\Access\AccessResult;
Chris@17 6 use Drupal\Core\Cache\RefinableCacheableDependencyInterface;
Chris@17 7 use Drupal\Core\Routing\Access\AccessInterface;
Chris@17 8 use Drupal\Core\Session\AccountInterface;
Chris@17 9 use Drupal\layout_builder\SectionStorageInterface;
Chris@17 10 use Symfony\Component\Routing\Route;
Chris@17 11
Chris@17 12 /**
Chris@17 13 * Provides an access check for the Layout Builder defaults.
Chris@17 14 *
Chris@18 15 * @ingroup layout_builder_access
Chris@18 16 *
Chris@17 17 * @internal
Chris@18 18 * Tagged services are internal.
Chris@17 19 */
Chris@17 20 class LayoutBuilderAccessCheck implements AccessInterface {
Chris@17 21
Chris@17 22 /**
Chris@17 23 * Checks routing access to the layout.
Chris@17 24 *
Chris@17 25 * @param \Drupal\layout_builder\SectionStorageInterface $section_storage
Chris@17 26 * The section storage.
Chris@17 27 * @param \Drupal\Core\Session\AccountInterface $account
Chris@17 28 * The current user.
Chris@17 29 * @param \Symfony\Component\Routing\Route $route
Chris@17 30 * The route to check against.
Chris@17 31 *
Chris@17 32 * @return \Drupal\Core\Access\AccessResultInterface
Chris@17 33 * The access result.
Chris@17 34 */
Chris@17 35 public function access(SectionStorageInterface $section_storage, AccountInterface $account, Route $route) {
Chris@17 36 $operation = $route->getRequirement('_layout_builder_access');
Chris@17 37 $access = $section_storage->access($operation, $account, TRUE);
Chris@18 38
Chris@18 39 // Check for the global permission unless the section storage checks
Chris@18 40 // permissions itself.
Chris@18 41 if (!$section_storage->getPluginDefinition()->get('handles_permission_check')) {
Chris@18 42 $access = $access->andIf(AccessResult::allowedIfHasPermission($account, 'configure any layout'));
Chris@18 43 }
Chris@18 44
Chris@17 45 if ($access instanceof RefinableCacheableDependencyInterface) {
Chris@17 46 $access->addCacheableDependency($section_storage);
Chris@17 47 }
Chris@17 48 return $access;
Chris@17 49 }
Chris@17 50
Chris@17 51 }