User reference fields with the available users restricted by role give a misleading error message when trying to reference an invalid user

Created on 6 August 2025, 16 days ago

Problem/Motivation

The error message given when a person tries to save an entity form while it is referencing a disallowed user can be misleading, saying for example that "The referenced entity (user: 4) does not exist." when in fact user 4 does exist, but does not have one of the roles permitted in the entityreference field configuration.

In most configurations the widget will be an autocomplete, or even a select, so invalid users will never be shown. However this can come up for people who copy paste because they know what input is expected and already have it, probably in entity pre-populate types of scenarios, and most commonly i bet when a user has been referenced with the autocomplete widget, the relevant role is taken away from that user, and somebody coming back to the form tries to save it (without even changing that user reference field).

The problem is that they will panic that the user got deleted somehow, then find it and see that it is there, and still not understand that in order to successfully reference that user they need to add the role back.

Steps to reproduce

  1. Create an entity reference field that references users ("userreference" field).
  2. Restrict the roles of the users that can be referenced.
  3. Attempt to reference a user that you know exists but does not have the relevant role by pasting in "Example Name (2)" or similar, where 2 is the user ID.
  4. You will get the incorrect and misleading message "The referenced entity (user: 2) does not exist."

Proposed resolution

Ideally, give a clear, specific message such as "The referenced entity (user: 4) must have one of the allowed roles (Editor)."

If not, vague but accurate messages such as "The referenced entity (user: 4) is not valid for referencing here"

Remaining tasks

  • Identify how feasible case-specific language is.
  • If feasible, decide if we need/want to include other more specific messaging for related situations while we do this (really only thinking of blocked users versus actually non-existent users)
  • Decide on the updated message language.
  • Implement.

User interface changes

Better messages.

Introduced terminology

None?

API changes

None.

Data model changes

None.

Release notes snippet

πŸ› Bug report
Status

Active

Version

11.2 πŸ”₯

Component

user.module

Created by

πŸ‡ΊπŸ‡ΈUnited States mlncn Minneapolis, MN, USA

Live updates comments and jobs are added and updated live.
  • Usability

    Makes Drupal easier to use. Preferred over UX, D7UX, etc.

  • Field UX

    Usability improvements related to the Field UI

Sign in to follow issues

Comments & Activities

  • Issue created by @mlncn
  • πŸ‡³πŸ‡ΏNew Zealand quietone

    Thanks for the report.

    If this problem was discovered on a version of Drupal that is not 11.x, add that information in the issue summary and leave the version at 11.x. In Drupal core changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to the Core change policies β†’ . Also mentioned on the version β†’ section of the list of issue fields documentation. Thanks.

Production build 0.71.5 2024