function DefaultMenuLinkTreeManipulators::menuLinkCheckAccess

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Menu/DefaultMenuLinkTreeManipulators.php \Drupal\Core\Menu\DefaultMenuLinkTreeManipulators::menuLinkCheckAccess()
  2. 10 core/lib/Drupal/Core/Menu/DefaultMenuLinkTreeManipulators.php \Drupal\Core\Menu\DefaultMenuLinkTreeManipulators::menuLinkCheckAccess()
  3. 11.x core/lib/Drupal/Core/Menu/DefaultMenuLinkTreeManipulators.php \Drupal\Core\Menu\DefaultMenuLinkTreeManipulators::menuLinkCheckAccess()

Checks access for one menu link instance.

Parameters

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

Return value

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

1 call to DefaultMenuLinkTreeManipulators::menuLinkCheckAccess()
DefaultMenuLinkTreeManipulators::checkAccess in core/lib/Drupal/Core/Menu/DefaultMenuLinkTreeManipulators.php
Performs access checks of a menu tree.

File

core/lib/Drupal/Core/Menu/DefaultMenuLinkTreeManipulators.php, line 197

Class

DefaultMenuLinkTreeManipulators
Provides a couple of menu link tree manipulators.

Namespace

Drupal\Core\Menu

Code

protected function menuLinkCheckAccess(MenuLinkInterface $instance) {
    $access_result = NULL;
    if ($this->account
        ->hasPermission('link to any page')) {
        $access_result = AccessResult::allowed();
    }
    else {
        $url = $instance->getUrlObject();
        // When no route name is specified, this must be an external link.
        if (!$url->isRouted()) {
            $access_result = AccessResult::allowed();
        }
        else {
            $access_result = $this->accessManager
                ->checkNamedRoute($url->getRouteName(), $url->getRouteParameters(), $this->account, TRUE);
        }
    }
    return $access_result->cachePerPermissions();
}

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