Role permissions not sorted in config export

Created on 12 March 2019, over 5 years ago
Updated 20 February 2023, over 1 year ago

Problem/Motivation

* When a helper module of mine does a $role->revokePermission('foo'),
* and i do a config export,
* i get a diff like this (note the missing '3' index)

diff --git a/config-sync/user.role.toggle_all.yml b/config-sync/user.role.toggle_all.yml
index 0ce46a0..35ac270 100644
--- a/config-sync/user.role.toggle_all.yml
+++ b/config-sync/user.role.toggle_all.yml
@@ -7,11 +7,10 @@ label: 'Toggle all'
 weight: -2
 is_admin: null
 permissions:
-  - 'abstractpermissions:role_toggle:toggle_all'
-  - 'access administration pages'
-  - 'access toolbar'
-  - 'role_toggle:administrator'
-  - 'role_toggle:debugger'
-  - 'role_toggle:design_manager'
-  - 'role_toggle:site_manager'
-  - 'role_toggle:translation_manager'
+  0: 'abstractpermissions:role_toggle:toggle_all'
+  1: 'access administration pages'
+  2: 'access toolbar'
+  4: 'role_toggle:debugger'
+  5: 'role_toggle:design_manager'
+  6: 'role_toggle:site_manager'
+  7: 'role_toggle:translation_manager'

When i then re-add it, i get:

diff --git a/config-sync/user.role.toggle_all.yml b/config-sync/user.role.toggle_all.yml
index 0ce46a0..8cb0074 100644
--- a/config-sync/user.role.toggle_all.yml
+++ b/config-sync/user.role.toggle_all.yml
@@ -10,8 +10,8 @@ permissions:
   - 'abstractpermissions:role_toggle:toggle_all'
   - 'access administration pages'
   - 'access toolbar'
-  - 'role_toggle:administrator'
   - 'role_toggle:debugger'
   - 'role_toggle:design_manager'
   - 'role_toggle:site_manager'
   - 'role_toggle:translation_manager'
+  - 'role_toggle:administrator'

Proposed resolution


Ex. 2 above shows that neither index normalization nor sorting work reliably.

\Drupal\user\Entity\Role::preSave:

    if (!$this->isSyncing()) {
      // Permissions are always ordered alphabetically to avoid conflicts in the
      // exported configuration.
      sort($this->permissions);
    }

Remaining tasks

Doit

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

πŸ› Bug report
Status

Fixed

Version

9.5

Component
ConfigurationΒ  β†’

Last updated 1 minute ago

Created by

πŸ‡©πŸ‡ͺGermany geek-merlin Freiburg, Germany

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024