annotate core/modules/layout_builder/src/Access/LayoutBuilderAccessCheck.php @ 5:12f9dff5fda9 tip

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