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:
if (\Drupal::currentUser()->isAnonymous()) {
// Run action.
}
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:
if (\Drupal::currentUser()->isAnonymous()) {
// Run action.
}