RuntimeException upon site "install from config" with multiple config import files (wrong sort order)

Created on 6 March 2024, 10 months ago
Updated 21 March 2024, 9 months ago

Problem/Motivation

When deploying an existing site configuration to a new site installation, the following exception is thrown:
RuntimeException: Adding non-existent permissions to a role is not allowed. The incorrect permissions are "create user_status workflow_transition"

This issue occurs because Drupal is unaware that the dynamic permission has a dependency on the workflow type and attempts to import the permission before the respective workflow type is created.

A similar error was encountered previously in 🐛 RuntimeException: Adding non-existent permissions to a role is not allowed Fixed . However, because it was resolved by adding a hook_ENTITY_TYPE_predelete to remove the permission from the user, it only handles the case of a workflow type being deleted.

Steps to reproduce

  1. create a workflow type.
  2. give permission 'Participate in workflow' to the user
  3. export the site configuration
  4. drop the database and perform a new site install from config using drush si --existing-config

Proposed resolution

Add a dependency between the dynamic permission and the respective workflow type so that Drupal resolves the configuration import sequence correctly, as per change-record Permissions can define dependencies

diff --git a/src/WorkflowPermissions.php b/src/WorkflowPermissions.php
index 04a8730..c909267 100644
--- a/src/WorkflowPermissions.php
+++ b/src/WorkflowPermissions.php
@@ -65,6 +65,9 @@ class WorkflowPermissions implements PermissionHandlerInterface {
           and re-enable 'Authenticated user'.</b></i>
           Role is enabled to create state transitions. (Determines
           transition-specific permission on the workflow admin page.)"),
+        'dependencies' => [
+          'config' => ["workflow.workflow.$type_id"]
+        ],
       ],
       // D7->D8-Conversion of 'schedule workflow transitions' permission to "schedule $type_id transition" (@see NodePermissions::create content).
       "schedule $type_id workflow_transition" => [
🐛 Bug report
Status

Fixed

Version

1.7

Component

Code

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

Comments & Activities

Production build 0.71.5 2024