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