Parsing error in UserFieldRole

Created on 1 December 2025, 2 months ago
Updated 2 December 2025, about 2 months ago

Problem/Motivation

The UserFieldRole plugin fails to compare correctly for a Role name that is more than a single word.

Steps to reproduce

Create a role: "First edit"
Create a user with this role
Create a "access rule only" and set the handler to user has role, selecting the role created above. Set it to control access to edit.
Add a selection rule which will cause the rule to be selected
Check a content item that would select the rule against the user created and note that it fails with: The 'Current user: Roles (in First edit)' access rule failed..

Proposed resolution

The code in UserFieldRole has this comment

// Roles are stored on the access policy with underscores "_" however they
// are stored in Drupal with a space. We need to replace that underscore
// with the space.

But \Drupal\user\RoleForm has this

 $form['id'] = [
      '#type' => 'machine_name',
      '#default_value' => $entity->id(),
      '#required' => TRUE,
      '#disabled' => !$entity->isNew(),
      '#size' => 30,
      '#maxlength' => 64,
      '#machine_name' => [
        'exists' => ['\Drupal\user\Entity\Role', 'load'],
      ],
    ];

And \Drupal\Core\Render\Element\MachineName::validateMachineName does not allow spaces.

Remaining tasks

Remove the parsing of underscores into space.

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States fathershawn New York

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.

No activities found.

Production build 0.71.5 2024