- Issue created by @adminbfe
The issue summary needs reformatting to be understandable. Are you saying this is a regression in 10.4.8 as compared to a prior version of Drupal? If so, then which version worked?
Title: Role::getPermissions() returns empty array in Drupal 10.4.8 with is_admin: false
Project: Drupal core
Version: 10.4.8
Component: User module
Category: Bug report
Priority: Normal
Steps Required to Reproduce the Bug:
Install Drupal 10.4.8.
Configure the administrator role with specific permissions (e.g., access administration pages, access content overview, access toolbar, administer content types, administer node fields, administer site configuration, view the administration theme).
Set is_admin: true for the administrator role using:
bash
Collapse
Wrap
Run
Copy
drush config:set user.role.administrator is_admin true
drush cache:rebuild
Test getPermissions():
bash
Collapse
Wrap
Run
Copy
drush php-eval "var_dump(\Drupal::entityTypeManager()->getStorage('user_role')->load('administrator')->getPermissions());"
Set is_admin: false:
bash
Collapse
Wrap
Run
Copy
drush config:set user.role.administrator is_admin false
drush cache:rebuild
Re-test getPermissions() using the same command.
Compare with toArray()['permissions'] and role_permission table:
bash
Collapse
Wrap
Run
Copy
drush php-eval "var_dump(\Drupal::entityTypeManager()->getStorage('user_role')->load('administrator')->toArray()['permissions']);"
mysql -u -p -e "SELECT permission FROM role_permission WHERE rid = 'administrator'"
Test hasPermission() for a user with the administrator role:
bash
Collapse
Wrap
Run
Copy
drush php-eval "var_dump(\Drupal::entityTypeManager()->getStorage('user')->load(1)->hasPermission('access administration pages'));"
What Behavior Were You Expecting?:
With is_admin: true, getPermissions() may return an empty array (as per Drupal’s optimization for administrator roles).
With is_admin: false, getPermissions() should return the assigned permissions (e.g., the 7 permissions listed above).
toArray()['permissions'] and role_permission table should match getPermissions() when is_admin: false.
hasPermission() should return true for assigned permissions.
What Happened Instead?:
With is_admin: true, getPermissions() returns array(0) [], which aligns with Drupal’s design.
With is_admin: false, getPermissions() still returns array(0) [], which is incorrect.
toArray()['permissions'] and role_permission table correctly list the 7 assigned permissions.
hasPermission() returns bool(true) for assigned permissions, confirming functionality.
All permissions are defined in \Drupal::service('user.permissions')->getPermissions().
System Information:
OS: Ubuntu (inferred from prompt).
Webserver: Apache (assumed, common for Drupal).
PHP Version: 8.1+ (required by Drupal 10.4.8, exact version unknown).
Drupal Version: 10.4.8.
Drupal Path: /var/www/drupal.
Database: MySQL, user drupalmain, database drupal_main.
Modules: Commerce modules partially uninstalled, core modules enabled.
Additional Notes:
No migration issues (no Drupal 7 history).
Cache cleared after every change.
No PHP errors in logs (assumed, no WSOD reported).
No pending database updates (drush updatedb reported no updates).
Proposed Solution:
Investigate Drupal\user\Entity\Role::getPermissions() to ensure it returns assigned permissions when is_admin: false.
Verify permission validation and caching logic in the user module.
Active
10.4 ✨
user.module
The issue summary needs reformatting to be understandable. Are you saying this is a regression in 10.4.8 as compared to a prior version of Drupal? If so, then which version worked?