Problem/Motivation
If no eligible referenceable entity exists, the user won't have anything to choose from, nor may they create an entity, nor may they do anything about it. It's just clutter and a distraction, in some cases amounting to a WTF, particularly if the field is marked required, so the form can't be submitted at all.
| non-required | required |
|---|---|
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Steps to reproduce
This scenario can be reproduced in two ways:
- When the target bundle that the entity reference field is referring to has no entities.
- When the target bundle that the entity reference field is referring to does not exist.
While the first situation sounds a bit irrational (yet likely to occur), the second situation is a possible edge case. In both the scenarios the user is left with no referenceable entities.
Proposed resolution
Providing a message that describes the problem to the user would help but there is a broader issue that needs discussion for a more complete solution.
Remaining tasks
Define the scope of this issue.
Come up with a complete solution.
Tests
User interface changes
Added descriptive text to ER widgets when no referencable entities are available.
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | 3038261-nr-bot.txt | 2.09 KB | needs-review-queue-bot |
| nobundle-required-radios.png | 26.46 KB | pancho | |
| nobundle-radios.png | 24.99 KB | pancho | |
| nobundle-required-select.png | 30.05 KB | pancho | |
| nobundle-select.png | 26.36 KB | pancho |
Issue fork drupal-3038261
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
Comment #2
panchoUnfortunately this is less easy and less straightforward than I hoped it would be, so we probably shouldn't do this step-by-step but should think it through to come up with a complete solution. Finally, the case of target bundles being set up correctly, but no entity being referenceable is the slightly more relevant situation.
Also, we might not want to mess with #required fields.
So if for any reason there's no referenceable entity available, and the field is non-required, we should:
For required fields, we shouldn't skip rendering the field for non-admin users, but instead show an sufficiently precise error message. The user might still not be able to change anything about it, so can't submit the form, but at least it is no longer a WTF experience, if properly explained.
Comment #4
seanbThis has been discussed for the media library widget in the UX meeting today: https://www.youtube.com/watch?v=MG0SgDMWsH0
I think the general consensus was we should try to show a helpful message to users instead of hiding the widget. So for editor users without permissions to edit the field or create new bundles of the referenced entity type it should be something like:
There are no [entity type] types available. Please contact a site administrator.For users with permissions to create new bundles of the entity type, it should be something like:
There are no [entity type] types available. Please <a href=":url">add a [entity type] type</a> and enable it for this field.Maybe we could change the scope of the issue to implement it here?
Comment #13
acbramley commentedI think the comments in #4 make more sense and would be easier to achieve than hiding the widget, therefore marking this as a feature.
Comment #14
sakthi_dev commentedComment #16
sakthi_dev commentedPlease review.
Comment #17
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #18
sakthi_dev commentedComment #19
smustgrave commentedWill need test coverage
Comment #20
kunal.sachdev commentedComment #21
kunal.sachdev commentedComment #22
srishtiiee commentedComment #23
lauriiiComment #24
tim.plunkettComment #25
srishtiiee commentedComment #27
acbramley commentedProvided some feedback, we still need tests and we haven't got any changes to the autocomplete widget which seems like this issue is targeted at from the IS.
Updating IS wording also.
Comment #30
quietone commentedentity_reference module is no longer in core.