Problem/Motivation
In a core Drupal entity reference field when target is a taxonomy, the widget "select" in the form displays the hierarchy of the terms to be selected, while when the same field type is defined as a sub-field in Custom Field, the widget "select" in the form displays all taxonomy terms flattened at the same level.
Steps to reproduce
Create a custom field with a sub field as an entity reference to a taxonomy.
In "Managed Form Display", widget Flexbox, set the widget as "select"
Create a core Entity Reference field to the same taxonomy (without using Custom Field).
Compare how the two fields are presented when editing the entity.
Proposed resolution
It would be fine to have the same behavior of the widget (or an option to display a flattened list ora a hierarchical list)
Remaining tasks
User interface changes
Yes
API changes
n/a
Data model changes
n/a
Issue fork custom_field-3563063
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
mario.awad commentedAn issue that might be related and that can hopefully be resolved at the same time is that the terms are always sorted alphabetically instead of by the weight that is set in the taxonomy terms listing when you reorder them.
Comment #5
apmsooner commentedThis turned out to be a simple fix by just letting the selection handler do its job. It wasn't because it was being ignored due to the limit passed in. So, don't do anything dumb like using a select|radios when you have 1000's of references and this should just work now. I also removed the extra level sanitization on the labels for radios widget as the handler already does that so ampersands in titles will no longer get double escaped. The order by weight in Taxonomy vocabulary is indeed now also acknowledged. Please test patch and report back.
Comment #6
svendecabooterTested this MR and seems to work as advertised.
Comment #7
apmsooner commentedThanks Sven!