Problem/Motivation
This is an add-on to #3089523: Use progressive disclosure to hide Sort options on entity reference fields until bundles are selected and #2900409: [Meta] Improve UI of Reference field settings form.
In the first referenced issue, the progressive disclosure concept was applied to the sort by element. The same concept applies to the sort direction element. The code in Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection::buildConfigurationForm()
adds the sort direction element only if the sort by element has a non-empty value (not equal to '_none' to be exact). However, if a user sets a value on the sort by element and then unchecks the 'target_bundles' element, the sort by element becomes hidden but the sort direction element remains visible.
Steps to reproduce
Add 1+ bundles to node entity type.
Add entity reference field to one of the node bundles.
Storage settings form: select node (or 'Content')
Expected result
Field settings form:
- check 1+ of the node bundles
- the 'Sort by' select element is shown
- the 'Sort direction' select element is NOT shown
- select item in the 'Sort by' select element
- the 'Sort direction' select element is shown
- uncheck all of the node bundles
- the 'Sort by' select element is NOT shown
- the 'Sort direction' select element is NOT shown
Actual result
Field settings form:
- check 1+ of the node bundles
- the 'Sort by' select element is shown
- the 'Sort direction' select element is NOT shown
- select item in the 'Sort by' select element
- the 'Sort direction' select element is shown
- uncheck all of the node bundles
- the 'Sort by' select element is NOT shown
- the 'Sort direction' select element is shown [the unexpected result]
Proposed resolution
Add a '#states' key to the sort direction element and remove the 'if condition' to its creation.
Remaining tasks
None.
User interface changes
None, except for show-hide elements according to progressive disclosure concept. For screenshots refer to the first referenced issue above.
API changes
None.
Data model changes
None.
Release notes snippet
Not applicable.