Skip to content
Snippets Groups Projects
Commit d0f2a3b6 authored by John Voskuilen's avatar John Voskuilen
Browse files

Issue #3419812: RuntimeException: Adding non-existent permissions to a role is not allowed

parent c16f0931
No related branches found
No related tags found
No related merge requests found
Pipeline #91118 passed with warnings
......@@ -366,13 +366,14 @@ class WorkflowManager implements WorkflowManagerInterface {
/**
* {@inheritdoc}
*/
public static function participateUserRoles(EntityInterface $workflow) {
public static function changeRolePermissions(EntityInterface $workflow, bool $grant) {
$type_id = $workflow->id();
$roles = workflow_get_user_role_names(NULL);
unset($roles[WORKFLOW_ROLE_AUTHOR_RID]);
// Enable/Disable roles.
foreach ($roles as $rid => $role) {
// Enable role.
$perms = ["create $type_id workflow_transition" => 1];
$perms = ["create $type_id workflow_transition" => $grant];
user_role_change_permissions($rid, $perms);
}
}
......
......@@ -46,14 +46,17 @@ interface WorkflowManagerInterface {
*/
/**
* Implements hook_WORKFLOW_insert().
* Implements hook_ENTITY_TYPE_insert() for 'workflow_type'.
* Implements hook_ENTITY_TYPE_delete() for 'workflow_type'.
*
* Make sure some roles are allowed to participate in a Workflow by default.
* Grant/Revoke all roles to participate in a Workflow by default.
*
* @param \Drupal\Core\Entity\EntityInterface $workflow
* The workflow object.
* @param bool $grant
* TRUE to grant, FALSE to revoke permissions to participate in workflow.
*/
public static function participateUserRoles(EntityInterface $workflow);
public static function changeRolePermissions(EntityInterface $workflow, bool $grant);
/**
* Implements hook_user_delete().
......
......@@ -151,10 +151,18 @@ function workflow_user_delete($account) {
* Implements hook_ENTITY_TYPE_insert() for 'workflow_type'.
*
* Is called when adding a new Workflow type.
* The technical name for the Workflow entity is 'workflow_type'.
*/
function workflow_workflow_type_insert(EntityInterface $entity) {
WorkflowManager::participateUserRoles($entity);
WorkflowManager::changeRolePermissions($entity, TRUE);
}
/**
* Implements hook_ENTITY_TYPE_delete() for 'workflow_type'.
*
* Is called when deleting a new Workflow type.
*/
function workflow_workflow_type_delete(EntityInterface $entity) {
WorkflowManager::changeRolePermissions($entity, FALSE);
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment