function SystemAdminMenuBlockAccessCheck::hasAccessToChildMenuItems

Same name in other branches
  1. 10 core/modules/system/src/Access/SystemAdminMenuBlockAccessCheck.php \Drupal\system\Access\SystemAdminMenuBlockAccessCheck::hasAccessToChildMenuItems()

Check that the given route has access to child routes.

Parameters

\Drupal\Core\Menu\MenuLinkInterface $link: The menu link.

\Drupal\Core\Session\AccountInterface $account: The account.

Return value

\Drupal\Core\Access\AccessResultInterface The access result.

File

core/modules/system/src/Access/SystemAdminMenuBlockAccessCheck.php, line 93

Class

SystemAdminMenuBlockAccessCheck
Access check for routes implementing _access_admin_menu_block_page.

Namespace

Drupal\system\Access

Code

protected function hasAccessToChildMenuItems(MenuLinkInterface $link, AccountInterface $account) : AccessResultInterface {
    $parameters = new MenuTreeParameters();
    $parameters->setRoot($link->getPluginId())
        ->excludeRoot()
        ->setTopLevelOnly()
        ->onlyEnabledLinks();
    $route = $this->router
        ->getRouteCollection()
        ->get($link->getRouteName());
    if ($route && empty($route->getRequirement('_access_admin_menu_block_page')) && empty($route->getRequirement('_access_admin_overview_page'))) {
        return AccessResult::allowed();
    }
    foreach ($this->menuLinkTree
        ->load(NULL, $parameters) as $element) {
        if (!$this->accessManager
            ->checkNamedRoute($element->link
            ->getRouteName(), $element->link
            ->getRouteParameters(), $account)) {
            continue;
        }
        // If access is allowed to this element in the tree, check for access to
        // any of its own children.
        if ($this->hasAccessToChildMenuItems($element->link, $account)
            ->isAllowed()) {
            return AccessResult::allowed();
        }
    }
    return AccessResult::neutral();
}

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