Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 293129

Configured actions created by User module cannot be edited

$
0
0

Problem/Motivation

The User module has some code that creates configured actions to add/remove a role from a user, when a new role is created.

The machine name (configuration entity ID) chosen for these actions is incompatible with the edit form in the Actions module UI.

So if you attempt to edit one of those auto-created actions, you get an error message saying:

 The machine-readable name must contain only lowercase letters, numbers, and underscores. 

screenshot of edit form with error message

To reproduce:
- Turn on Actions module
- Go to admin/config/system/actions
- Click Edit for one of the "Add ... role to " actions
- Click Save and you will see the message
- It looks like from that screen that you should be able to edit the machine name, but this is actually not possible as the machine name field is read-only (it is configuration and you cannot change its ID once it is created).

Proposed resolution

Fix the User module so that the actions it creates have legal machine names. The code that creates the actions is in user.module:

function user_user_role_insert(RoleInterface $role) {
...
  $add_id = 'user_add_role_action.' . $role->id();
  if (!Action::load($add_id)) {
    $action = Action::create([
      'id' => $add_id,
 ...
  }
  $remove_id = 'user_remove_role_action.' . $role->id();
  if (!Action::load($remove_id)) {
    $action = Action::create([
      'id' => $remove_id,
  ...

OR

Fix the Actions module so that it allows . in the machine name in the edit form. The code for that is in
core/modules/action/src/Form/ActionFormBase.php:

    $form['id'] = [
      '#type' => 'machine_name',
      '#default_value' => $this->entity->id(),
      '#disabled' => !$this->entity->isNew(),
      '#maxlength' => 64,
      '#description' => $this->t('A unique name for this action. It must only contain lowercase letters, numbers and underscores.'),
      '#machine_name' => [
        'exists' => [$this, 'exists'],
      ],
    ];

Allowing . can be specified by changing the default for the #machine_name['replace_pattern'] property. It defaults to '[^a-z0-9_]+'. If this is changed the #description also needs to be changed.

I think this is the best option since config will most likely already contain uneditable actions.

Remaining tasks

Decide which option makes the most sense. Make a patch.

User interface changes

All configured actions will be editable.

API changes

None.

Data model changes

None.

Release notes snippet


Viewing all articles
Browse latest Browse all 293129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>