Drupal 8: Detecting An Anonymous User

28th June 2016

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


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

  1. if (\Drupal::currentUser()->isAnonymous()) {
  2. // Run action.
  3. }


Add new comment

The content of this field is kept private and will not be shown publicly.