function UserLoginBlock::blockAccess

Same name in other branches
  1. 9 core/modules/user/src/Plugin/Block/UserLoginBlock.php \Drupal\user\Plugin\Block\UserLoginBlock::blockAccess()
  2. 8.9.x core/modules/user/src/Plugin/Block/UserLoginBlock.php \Drupal\user\Plugin\Block\UserLoginBlock::blockAccess()
  3. 10 core/modules/user/src/Plugin/Block/UserLoginBlock.php \Drupal\user\Plugin\Block\UserLoginBlock::blockAccess()

Overrides BlockPluginTrait::blockAccess

File

core/modules/user/src/Plugin/Block/UserLoginBlock.php, line 85

Class

UserLoginBlock
Provides a 'User login' block.

Namespace

Drupal\user\Plugin\Block

Code

protected function blockAccess(AccountInterface $account) {
    $route_name = $this->routeMatch
        ->getRouteName();
    if ($account->isAnonymous() && !in_array($route_name, [
        'user.login',
        'user.logout',
    ])) {
        return AccessResult::allowed()->addCacheContexts([
            'route.name',
            'user.roles:anonymous',
        ]);
    }
    return AccessResult::forbidden();
}

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