Problem/Motivation
When an entity_reference field's target_bundles setting allows more than one bundle, and only some of those bundles have Entity Reference Field Override enabled, the "Field Overrides" section rendered on the parent entity's edit form incorrectly shows override selectors for every field configured on any of the allowed target bundles — not just the fields belonging to the bundle that is actually referenced.
This happens in EntityReferenceFieldOverrideHooks::fieldWidgetSingleElementFormAlter(). The method loads override configuration for every bundle in the field's target_bundles handler setting via entity_reference_field_override_get_bundle_configs(). When the specifically-referenced bundle has no override configuration of its own, the code falls into an else branch that merges (unions) the override fields from every other configured bundle instead of showing nothing:
$override_fields = []; if ($target_bundle && isset($bundle_override_configs[$target_bundle])) { $override_fields = $bundle_override_configs[$target_bundle]; } else { foreach ($bundle_override_configs as $config) { $override_fields = array_merge($override_fields, $config); } $override_fields = array_unique($override_fields); }
Because the referenced field does not actually exist on the referenced bundle, entity_reference_field_override_get_field_options() and entity_reference_field_override_get_field_label() silently fail to resolve it and fall back to a "Default only" select with a humanized machine name as the label — so the symptom is a set of oddly-labeled override selectors, each offering only "Default", for fields that don't belong to the entity actually being referenced.
The same leaked field list is also exposed via the data-erfo-override-fields attribute and consumed unfiltered by OverrideOptionsController::getOverrideOptions(), so the AJAX-driven refresh (triggered when the autocomplete selection changes) reproduces the same issue.
Steps to reproduce
- Create two content types/bundles, A and B, both allowed as
target_bundleson the same sharedentity_referencefield. - Enable field overrides on bundle A only (Field Override Settings on the content type edit form), and select one or more fields under "Overridable Fields" that exist only on A (e.g. a list or boolean field not present on B).
- Leave bundle B with field overrides disabled (no configuration).
- Edit an entity that has the shared reference field, and reference an entity of bundle B.
- Expand the "Field Overrides" section for that reference.
Expected: no "Field Overrides" section is shown (bundle B has no overridable fields configured).
Actual: the "Field Overrides" section appears and shows selectors for bundle A's overridable fields, each offering only a "Default" option and labeled with a humanized version of A's field machine names.
Proposed resolution
In EntityReferenceFieldOverrideHooks::fieldWidgetSingleElementFormAlter(), stop falling back to a union of every configured bundle's override fields. The fields shown must always be exactly the specifically-referenced bundle's own configured list — and empty when no bundle is selected yet or the referenced bundle has no overrides configured:
$override_fields = $target_bundle ? ($bundle_override_configs[$target_bundle] ?? []) : [];This replaces the existing if ($target_bundle && isset($bundle_override_configs[$target_bundle])) { ... } else { foreach (...) { array_merge(...) } } block.
The $all_override_fields union used to build the data-erfo-override-fields attribute (consumed by the AJAX endpoint) should be removed in favor of reusing the same $override_fields value. This is safe: per js/field-override.js::updateOverrideOptions(), the client-side AJAX refresh only ever updates the options/label of override <select> elements already present in the DOM — it never creates new ones — so the set of fields a given widget instance can ever show is fixed at server-render time regardless of what this attribute contains. Removing the union eliminates the leak with no loss of existing functionality.
No schema or config changes are required; this is a pure runtime logic fix in already-shipped module code.
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork erfo-3624136
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 #5
mighty_webberFixed and merged
Comment #7
mighty_webberTagged and Released.