Snippet: How to check for user access or permission in Drupal 8

May 06, 2016 · by Tim Kamanin

In Drupal 7 you did user_access(), but in D8 you should do:


// Get current user
$user = \Drupal::currentUser();

// Check for permission
$user->hasPermission('administer content');

Want to get more 🔥 tips like this one?

Subscribe to get notified about new dev tutorials