Skip to content

Instantly share code, notes, and snippets.

@woutersf
Last active January 4, 2017 08:51
Show Gist options
  • Save woutersf/a166f7bd1cdf0a4427457ae1160c3c30 to your computer and use it in GitHub Desktop.
Save woutersf/a166f7bd1cdf0a4427457ae1160c3c30 to your computer and use it in GitHub Desktop.
drupal8 test if user is logged in
<?php
//If anonymous
if (\Drupal::currentUser()->isAnonymous()) {
// Do something..
}
//if user has role
$roles = \Drupal::currentUser()->getRoles();
if(!in_array("administrator", $roles)) {
// Do something..
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment