Last active
January 4, 2017 08:51
-
-
Save woutersf/a166f7bd1cdf0a4427457ae1160c3c30 to your computer and use it in GitHub Desktop.
drupal8 test if user is logged in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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