Drupal 8: Detecting An Anonymous User

Tuesday, June 28, 2016 - 10:38

To find out if the current user is anonymous use the following.

\Drupal::currentUser()->isAnonymous();

This can be used as part of an if statement like this:

1
2
3
if (\Drupal::currentUser()->isAnonymous()) {
  // Run action.
}
Category: 
Tags: 
philipnorton42's picture

Philip Norton

Phil is the founder and administrator of #! code and is an IT professional working in the North West of the UK.
Google+ | Twitter

Add new comment