LayoutBuilderAccessCheck.php

Same filename in other branches
  1. 9 core/modules/layout_builder/src/Access/LayoutBuilderAccessCheck.php
  2. 10 core/modules/layout_builder/src/Access/LayoutBuilderAccessCheck.php
  3. 11.x core/modules/layout_builder/src/Access/LayoutBuilderAccessCheck.php

Namespace

Drupal\layout_builder\Access

File

core/modules/layout_builder/src/Access/LayoutBuilderAccessCheck.php

View source
<?php

namespace Drupal\layout_builder\Access;

use Drupal\Core\Access\AccessResult;
use Drupal\Core\Cache\RefinableCacheableDependencyInterface;
use Drupal\Core\Routing\Access\AccessInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\layout_builder\SectionStorageInterface;
use Symfony\Component\Routing\Route;

/**
 * Provides an access check for the Layout Builder defaults.
 *
 * @ingroup layout_builder_access
 *
 * @internal
 *   Tagged services are internal.
 */
class LayoutBuilderAccessCheck implements AccessInterface {
    
    /**
     * Checks routing access to the layout.
     *
     * @param \Drupal\layout_builder\SectionStorageInterface $section_storage
     *   The section storage.
     * @param \Drupal\Core\Session\AccountInterface $account
     *   The current user.
     * @param \Symfony\Component\Routing\Route $route
     *   The route to check against.
     *
     * @return \Drupal\Core\Access\AccessResultInterface
     *   The access result.
     */
    public function access(SectionStorageInterface $section_storage, AccountInterface $account, Route $route) {
        $operation = $route->getRequirement('_layout_builder_access');
        $access = $section_storage->access($operation, $account, TRUE);
        // Check for the global permission unless the section storage checks
        // permissions itself.
        if (!$section_storage->getPluginDefinition()
            ->get('handles_permission_check')) {
            $access = $access->andIf(AccessResult::allowedIfHasPermission($account, 'configure any layout'));
        }
        if ($access instanceof RefinableCacheableDependencyInterface) {
            $access->addCacheableDependency($section_storage);
        }
        return $access;
    }

}

Classes

Title Deprecated Summary
LayoutBuilderAccessCheck Provides an access check for the Layout Builder defaults.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.