Problem/Motivation

Error:
TypeError: array_keys(): Argument #1 ($array) must be of type array, null given in array_keys() (line 224 of modules/contrib/administerusersbyrole/administerusersbyrole.module).

Issue:

function administerusersbyrole_form_user_form_submit(array $form, FormStateInterface $form_state) {
  // Preserve the setting for any roles that were not visible in the form.
  $preserve = array_diff($form['account']['roles']['#default_value'], array_keys($form["account"]["roles"]["#options"]));
  $roles = array_merge($form_state->getValue('roles'), $preserve);
  $form_state->setValue('roles', $roles);
}

Steps to reproduce

- Log in as a user who does not have permission to see/assign any roles on the user edit form (e.g. no assignable roles are available to them, or the roles element is otherwise not built with #options).
- Edit a user account and submit the form.
- Observe the fatal error.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

tvalimaa created an issue.