Closed (duplicate)
Project:
Drupal core
Version:
11.x-dev
Component:
field system
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
12 Jul 2019 at 11:15 UTC
Updated:
1 Aug 2023 at 11:30 UTC
Jump to comment: Most recent, Most recent file

Comments
Comment #2
amateescu commentedThere is a long history with this bundle selection element and why it's required without any bundle selected by default. If you're keen to read up on all the old discussion about this, you can start with #1847596-119: Remove Taxonomy term reference field in favor of Entity reference (point 8. from @xjm's comment) and #1953444: Make 'target bundles' required on the Entity reference instance settings form which actually implemented the change.
To answer the three points from the current IS:
That sounds like a problem on its own, and should be fixed by the reference issue.
That's actually a good thing, because the entities from the new bundle shouldn't be exposed automatically to (potentially) anonymous users of the site.
That's also a good thing because it enforces consistency in the (config) data model of the site.
As for the proposed resolution, making the bundle selection optional will introduce a usability regression on this form, so all we can do is provide the "Select all" feature, mentioned in #1953444-11: Make 'target bundles' required on the Entity reference instance settings form as well.
Comment #3
manuel.adanDespite opening an entity form with entity reference fields to anonymous users is possible, I think it is not the most common situation. Anyway, this change would not reduce security, since any new bundle would not be added automatically to existing reference fields that already have some bundle selected, working as they did before the new bundle was added.
If one module just requires an entity type, regardless the existing bundles, developer is forced to introduce dependencies on each module that defines any bundle just to satisfy the field reference restrictions. IMOH, it has no sense since it is not a real dependency.
I finally created a view with a reference display that list any node type, and I used the view selection mode in the entity reference field. I got fine control on the reference field results as a plus for the extra work. Other option could be implement a custom selection method plugin.
At the end, site builders will find a way to do what the site needs. I think that by cutting options with no good reason for it we just only make things hard.
Comment #7
artemboikoHi there,
There are a possibility just to set $form['target_bundles']['#required'] to FALSE or add new option Select all with NULL key. In web/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php other logic for work with NULL is existed here.
But fully agree with @amateescu with all points, and seems like no need to add this.
In case if we need Select all option we can create view entity reference without filtering by bundle.
And for this:
We can use Is not one of filter parameter in view filter by type.
Comment #8
andypostIt looks more like documentation issue, ERSelection plugins needs better examples (when better to create own selection plugin)
Other issues with views selection could benefit more attention if it will be proposed in some official docs
Comment #14
jonathanshawWe have another issue focused on 'select all': #3031637: Entity reference: allow specifiying that every bundle is allowed.
So this is a combination of duplicate/won't fix.