You are here

protected function UserLoginBlock::blockAccess in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/user/src/Plugin/Block/UserLoginBlock.php \Drupal\user\Plugin\Block\UserLoginBlock::blockAccess()
  2. 9 core/modules/user/src/Plugin/Block/UserLoginBlock.php \Drupal\user\Plugin\Block\UserLoginBlock::blockAccess()

File

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

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();
}