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;
}
}
// <-
----
| Comment | File | Size | Author |
|---|---|---|---|
| #20 | acl-validate-changes-3389445-20.patch | 1.09 KB | ad0z |
| #19 | acl-validate-changes-3389445-19.patch | 1.09 KB | ad0z |
| #18 | acl-validate-changes-3389445-for8.x-1.1.patch | 1.24 KB | kubokura |
| #17 | acl-validate-changes-3389445-17.patch | 1.23 KB | ad0z |
| #12 | acl-validate-changes-3389445-12.patch | 1.12 KB | ad0z |
Comments
Comment #2
kubokura commentedComment #3
kubokura commentedComment #4
kubokura commentedComment #5
kubokura commentedComment #6
kubokura commentedComment #7
kubokura commentedComment #8
salvisAs you can see above, pasting code as text does not work.
Such version number have never existed.
Please provide a patch against the current -dev version.
Comment #9
kubokura commentedThank you for reply, and sorry for typo.
wrong: v1.1.0 to v1.0.0-beta1
correct: 8.x-1.1 to 8.x-1.0-beta1
And here is a patch against 8.x-1.x-dev (dev-1.x 963031f).
best regards,
Comment #10
salvisComment #11
salvisNever mind the D9.5 — it's the code for 8 and 9. The test bot says
By now we have a 2.x branch for D10, and the patch needs to go against 2.x-dev now. The D8 and D10 branches haven't diverged much yet, the code that you're concerned with is probably still the same.
Comment #12
ad0z commentedI checked the issue and I think we should just let
EntityAutocomplete::validateEntityAutocompletevalidate this element, instead of trying to validate it ourselves, it will validate and set errors like normal entity_autocomplete form element, it will resolve this issue as well because notstatic::extractEntityIdFromAutocompleteInputonly is called there, butstatic::matchEntityByTitleas well.I've tested it as much as I could but I would be good if somebody with live usage of
acl_edit_formcould test it as well.I have prepared patch which implement it, so please take a look.
Comment #13
ad0z commentedComment #14
kubokura commentedHi, thank you for the patch. Unfortunately the patch doesn't work well for me.
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. The username isn't added in "Current users" list without "Invalid user specified." error message.
best regards,
Comment #15
ad0z commented@kubokura are you sure you applying the patch correctly? "Invalid user specified" error message is removed and all errors are handled with
EntityAutocomplete::validateEntityAutocompleteand they are different.What version of the module are you using?
Comment #16
kubokura commentedHi, @ad0z, I'm sorry. I applied the patch against acl 8.x-1.1 on Drupal 9.5.11.
Please disregard my comment of Oct 25.
I still can't upgrade to D10 due to composer error, so I can't apply the patch correctly at this moment.
Comment #17
ad0z commented@kubokura I've prepared patch for
8.x-1.1, attaching above.Comment #18
kubokura commentedHi, @ad0z, thank you for the new patch.
The same symptom "The username isn't added in "Current users" list without "Invalid user specified." error message." occurs, so I modified your patch a little, and it works for me.
+ $uid = $form_state->getValue([$acl_wrapper_key, 'add']);
-> + $uid = $form_state->getValue([$acl_wrapper_key, 'view', 'add']);
Comment #19
ad0z commented@kubokura thanks for finding it, my patch didn't support nested form elements, and I think your patch need update as it hard code element key to be 'view'.
I am attaching patch to
8.x-1.xand2.x, could you test one for8.x-1.x?Comment #20
ad0z commentedComment #21
kubokura commentedHi, @ad0z, thank you for the update. acl-validate-changes-3389445-19.patch works for me. Username is entered successfully without selecting suggested username.
Comment #22
dillix commentedWe need MR for this issue.
Comment #23
nevergone#3389445-20: "Invalid user specified." occurs for auto-complete user field if you don't select suggested username manually tested and works well. Thanks!
Comment #25
nevergoneCommitted.