(Issue also present in 8.x-1.5.)
Summary: My entity reference includes relationships that are necessary for the sort criteria. However, these criteria are ignored when the filter options are displayed.
I have a website with nodes arranged hierarchically via the menu. If I create a view of such nodes, I can mirror the menu structure in an Entity Reference display by:
- creating a relationship between each node and its menu link (via Menu Entity Index)
- creating a relationship between each node and its parent's menu link (via Menu Entity Index)
- creating a relationship between the parent menu link and the parent node (via Menu Entity Index)
- formatting the display as using TreeHelper (Adjacency model), with the node ID as the Main field and the parent ID as the Parent field (via Views Tree)
- sorting by node weight then parent weight
The preview shows the rows sorted correctly. However, when I use this display as the filter source for another view, the sort criteria are effectively ignored.
The view (with irrelevant displays removed) is as follows…
uuid: 75af3e80-cdbc-44b0-a5b5-e6511384c14b
langcode: en
status: true
dependencies:
config:
- node.type.page
module:
- menu_entity_index
- menu_link_content
- node
- user
- views_alias_filter
- views_conditional
- views_field_compare
- views_tree
id: test
label: Test
module: views
description: ''
tag: ''
base_table: node_field_data
base_field: nid
display:
default:
id: default
display_title: Default
display_plugin: default
position: 0
display_options:
fields:
nid:
id: nid
table: node_field_data
field: nid
relationship: none
group_type: group
admin_label: ''
entity_type: node
entity_field: nid
plugin_id: field
label: ID
exclude: true
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
click_sort_column: value
type: number_integer
settings:
thousand_separator: ''
prefix_suffix: true
group_column: value
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
level:
id: level
table: menu_entity_index
field: level
relationship: entity_id
group_type: group
admin_label: ''
plugin_id: standard
label: Level
exclude: true
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
title:
id: title
table: node_field_data
field: title
relationship: none
group_type: group
admin_label: ''
entity_type: node
entity_field: title
plugin_id: field
label: ''
exclude: true
alter:
alter_text: true
text: '{{ views_conditional_field }} {{ title }}'
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: false
ellipsis: false
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: false
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
click_sort_column: value
type: string
settings:
link_to_entity: true
group_column: value
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
nid_1:
id: nid_1
table: node_field_data
field: nid
relationship: node_id
group_type: group
admin_label: ''
entity_type: node
entity_field: nid
plugin_id: field
label: 'Parent ID'
exclude: true
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
click_sort_column: value
type: number_integer
settings:
thousand_separator: ''
prefix_suffix: true
group_column: value
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
views_conditional_field:
id: views_conditional_field
table: views_conditional
field: views_conditional_field
relationship: none
group_type: group
admin_label: ''
plugin_id: views_conditional_field
label: ''
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: false
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
if: level
condition: eq
equalto: '3'
then: '— {{ title }}'
then_translate: 0
or: '{{ title }}'
or_translate: 0
strip_tags: 0
pager:
type: none
options:
offset: 0
exposed_form:
type: basic
options:
submit_button: Apply
reset_button: false
reset_button_label: Reset
exposed_sorts_label: 'Sort by'
expose_sort_order: true
sort_asc_label: Asc
sort_desc_label: Desc
access:
type: perm
options:
perm: 'access content'
cache:
type: tag
options: { }
empty: { }
sorts:
weight:
id: weight
table: menu_link_content_data
field: weight
relationship: entity_id
group_type: group
admin_label: ''
entity_type: menu_link_content
entity_field: weight
plugin_id: standard
order: ASC
expose:
label: ''
field_identifier: ''
exposed: false
weight_1:
id: weight_1
table: menu_link_content_data
field: weight
relationship: parent_id
group_type: group
admin_label: ''
entity_type: menu_link_content
entity_field: weight
plugin_id: standard
order: ASC
expose:
label: ''
field_identifier: ''
exposed: false
arguments:
nid:
id: nid
table: node_field_data
field: nid
relationship: none
group_type: group
admin_label: ''
entity_type: node
entity_field: nid
plugin_id: node_nid
default_action: 'not found'
exception:
value: all
title_enable: false
title: All
title_enable: false
title: ''
default_argument_type: fixed
default_argument_options:
argument: ''
default_argument_skip_url: false
summary_options:
base_path: ''
count: true
override: false
items_per_page: 25
summary:
sort_order: asc
number_of_records: 0
format: default_summary
specify_validation: false
validate:
type: none
fail: 'not found'
validate_options: { }
break_phrase: true
not: false
filters:
status:
id: status
table: node_field_data
field: status
entity_type: node
entity_field: status
plugin_id: boolean
value: '1'
group: 1
expose:
operator: ''
operator_limit_selection: false
operator_list: { }
type:
id: type
table: node_field_data
field: type
entity_type: node
entity_field: type
plugin_id: bundle
value:
page: page
group: 1
expose:
operator_limit_selection: false
operator_list: { }
url_alias_filter:
id: url_alias_filter
table: node_field_data
field: url_alias_filter
relationship: none
group_type: group
admin_label: ''
entity_type: node
plugin_id: url_alias_filter
operator: starts
value: /resources/
group: 1
exposed: false
expose:
operator_id: ''
label: ''
description: ''
use_operator: false
operator: ''
operator_limit_selection: false
operator_list: { }
identifier: ''
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
placeholder: ''
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
field_comparison:
id: field_comparison
table: views
field: field_comparison
relationship: none
group_type: group
admin_label: ''
plugin_id: field_comparison
operator: '!='
value: ''
group: 1
exposed: false
expose:
operator_id: ''
label: ''
description: ''
use_operator: false
operator: ''
operator_limit_selection: false
operator_list: { }
identifier: ''
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
left_field: nid
right_field: nid_1
filter_groups:
operator: AND
groups:
1: AND
style:
type: default
options:
grouping: { }
row_class: ''
default_row_class: true
row:
type: fields
options:
default_field_elements: true
inline: { }
separator: ''
hide_empty: false
query:
type: views_query
options:
query_comment: ''
disable_sql_rewrite: false
distinct: false
replica: false
query_tags: { }
relationships:
entity_id:
id: entity_id
table: menu_entity_index
field: entity_id
relationship: none
group_type: group
admin_label: 'Menu link'
plugin_id: standard
required: true
parent_id:
id: parent_id
table: menu_entity_index
field: parent_id
relationship: none
group_type: group
admin_label: 'Parent link'
plugin_id: standard
required: true
node_id:
id: node_id
table: menu_entity_index
field: node_id
relationship: parent_id
group_type: group
admin_label: Parent
plugin_id: standard
required: true
header: { }
footer: { }
display_extenders: { }
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url
- 'user.node_grants:view'
- user.permissions
tags: { }
…
entity_reference_1:
id: entity_reference_1
display_title: 'All (ER)'
display_plugin: entity_reference
position: 1
display_options:
pager:
type: none
options:
offset: 0
arguments: { }
style:
type: tree_entity_reference_selection
options:
row_class: ''
default_row_class: true
type: ul
main_field: nid
parent_field: nid_1
collapsible_tree: '0'
search_fields:
title: title
nid: 0
nid_1: 0
row:
type: entity_reference
options:
default_field_elements: true
inline: { }
separator: ''
hide_empty: false
defaults:
fields: true
arguments: false
display_description: ''
display_extenders:
views_merge_rows:
merge_rows: false
field_config: { }
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- 'user.node_grants:view'
- user.permissions
tags: { }
Comments
Comment #2
maximkashubaComment #3
maximkashubarobbm,
Can't reproduce the bug with Menu Entity Index module (sorting with the module views relations to menu items).
The results for the entity entityreference filter in a view are the same as for origin/source entity reference view and sorted in the same order.
Comment #4
robbm commentedThanks for investigating. I thought I'd found that it was any relationship, but perhaps it was the inclusion of views_tree…
I'll try to put together the simplest set of steps to reproduce the issue repeatedly.
Comment #5
robbm commentedSteps to reproduce:
mkdir EntityReferenceFilterTestProjectcomposer create-project "drupal/recommended-project:~9" EntityReferenceFilterTestProject/repocd EntityReferenceFilterTestProject/reposed -i 's/"stable"/"dev"/' composer.json # Or for macOS: sed -i '' 's/"stable"/"dev"/' composer.jsoncomposer require drupal/entityreference_filter drupal/menu_entity_index drupal/views_treeNote that the sort order in the preview now echoes the menu order.
Note that sort order in the drop-down for the field created above is not the same as previously seen in the preview, i.e. it no longer echoes the menu order. (Not exactly the original issue, but closely related.)
Note that sort order in the drop-down for the filter is not the same as previously seen in the preview, i.e. it no longer echoes the menu order.
Comment #6
robbm commentedIn hindsight, the drop-down might be respecting the sort criteria, just not the Views Tree "grouping". Will double check and come back…