"Invalid user specified." occurs for auto-complete user field if you don't select suggested username

Created on 25 September 2023, about 1 year ago
Updated 30 October 2023, about 1 year ago

Problem/Motivation

If you hit the [Add user] button without selecting suggested username under the auto-complete user field, you get a "Invalid user specified." error message.
I found this symptom was reproduced since acl 8.x-1.0-beta2.

Steps to reproduce

1. Copy a username from other web page or txt file, and paste it to the user field.
2. Suggested username appears under the auto-complete user field, but ignore it, and hit the [Add user] button.
3. Get the "Invalid user specified." error message.

Expected behavior

Username, if it is correct, can be entered successfully without selecting suggested username.

Backgroud

When duplicating a node, we need to enter multiple usernames in user field of Access Control tab manually, for example, by copying and pasting from usernames list of the original node.
So it is better each action of selecting suggested username is not necessary.

Proposed resolution

Reverting part of acl.admin.inc of v1.1.0 to v1.0.0-beta1 works OK.
vi acl.admin.inc
----
L.115
elseif (!empty($triggering_element['#value']) && $triggering_element['#value'] == $form['add_button']['#value'] && !empty($form['add']['#value'])) {
$value = $form['add']['#value'];
// if ($match = EntityAutocomplete::extractEntityIdFromAutocompleteInput($value)) {
// $user = @User::load($match);
// }
// if (empty($user)) {
// $form_state->setError($form['add'], t("Invalid user specified."));
// }
// else {
// $user_list[$user->id()] = $user->getDisplayName();
// $form['add']['#value'] = '';
// }
// }
// ->
$match = EntityAutocomplete::extractEntityIdFromAutocompleteInput($value);
if ($match === NULL) {
$user = \Drupal::database()->query("SELECT u.uid, ud.name FROM {users} u INNER JOIN {users_field_data} ud ON u.uid = ud.uid WHERE ud.name = :name", [
'name' => $value,
])->fetchObject();
}
else {
$user = \Drupal::database()->query("SELECT u.uid, ud.name FROM {users} u INNER JOIN {users_field_data} ud ON u.uid = ud.uid WHERE u.uid = :id", [
'id' => $match,
])->fetchObject();
}
if (!$user) {
$form_state->setError($form['add'], t("Invalid user specified."));
}
else {
$user_list[$user->uid] = $user->name;
$form['add']['#value'] = NULL;
}
}
// <-
----

🐛 Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

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

Comments & Activities

Production build 0.71.5 2024