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

06 May · by Tim Kamanin · 1 min read

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

<?php

// 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

Comments