Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By fubhy on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Issue links:
Description:
Previously, role permission assignments were stored in a {role_permissions} table in the database. Instead, we are now storing the permissions of a role directly on the Role configuration entity(see User roles are now configurables).
Instead of using procedural wrappers you can now retrieve or manipulate a role's permission through a set of methods defined in the RoleInterface.
Drupal 7
// Retrieving a list of granted permissions for a role
$permissions = user_role_permissions($rids);
// Checking if a role has a permission.
$permissions = user_role_permissions($rids);
isset($permissions[$rid]['access content']);
// Granting permissions.
user_role_grant_permissions($rid, array('access content', 'post comments'));
// Revoking permissions.
user_role_revoke_permissions($rid, array('access content'));
Drupal 8
// Retrieving a list of granted permissions for a role
$role->getPermissions();
// Checking if a role has a permission.
$role->hasPermission('access content');
// Granting permissions.
$role->grantPermission('post comments');
// Revoking permissions.
$role->revokePermission('access content');
Impacts:
Module developers