Problem/Motivation

The taxonomy terms are not sorted following any of the different sort criteria (name, Term ID) or the sort order as set on the edit tab of the field when displayed as checkboxes or as select list.
Instead they are displayed per vocabulary (with the select list displaying the vocabulary name as well) and for each vocabulary sorted by weight.

Proposed resolution

Remaining tasks

User interface changes

API changes

CommentFileSizeAuthor
#3 2412553.patch927 bytesamateescu
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ifrik’s picture

Berdir’s picture

This is because the selection plugin is using taxonom_get_tree(), which can only do that. There is no other way to display a term hierarchy.

A quickfix would be to hide the sort option for term references, a more complete fix to make that behavior configurable.

amateescu’s picture

Status: Active » Needs review
FileSize
927 bytes

I think we need to go with the simple fix for 8.0.x and maybe look into adding support for sorting \Drupal\taxonomy\TermStorageInterface::loadTree() in 8.1.x.

jibran’s picture

+++ b/core/modules/taxonomy/src/Plugin/EntityReferenceSelection/TermSelection.php
@@ -45,6 +45,11 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
+    // Sorting is not possible for taxonomy terms because we use
+    // \Drupal\taxonomy\TermStorageInterface::loadTree() to retrieve matches.

I like #3 but can we let user know about this behavior? Something like, "Terms are only sorted by their weight" as a markup.
Maybe create a followup and add a link here in comments.

amateescu’s picture

@jibran, why do you think that adding that piece of #markup in there will help users? They have no way to act upon it anyway, so IMO it will be just confusing.

jibran’s picture

Status: Needs review » Reviewed & tested by the community

I agree it's TMI.

claudiu.cristea’s picture

@amateescu,

[...] and maybe look into adding support for sorting \Drupal\taxonomy\TermStorageInterface::loadTree() in 8.1.x

Shouldn't we fill an issue for that? :)

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Can this bug be tested?

amateescu’s picture

Status: Needs work » Needs review

Hm.. that's tricky to answer. The current patch just removed the sort option from the UI, so all we can test is that it doesn't show up anymore.

However, if we wanted to take the other route and add sorting capability to \Drupal\taxonomy\TermStorageInterface::loadTree(), that should definitely be tested.

amateescu’s picture

Status: Needs review » Reviewed & tested by the community

Given that the taxonomy reference field doesn't have any sort either, this is not a regression for #1847596: Remove Taxonomy term reference field in favor of Entity reference, and asserting that a select element is not visible in the UI is not really helpful if we can't pair it with a positive assertion on the same xpath :)

amateescu’s picture

This is the pre-existing issue that we can use for adding sorting capability to the taxonomy selection plugin: #2372225: Add sort setting for taxonomy term autocomplete results

alexpott’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -Needs tests

This issue is a normal bug fix, and doesn't include any disruptive changes, so it is allowed per https://www.drupal.org/core/beta-changes. Committed 8dbdbd7 and pushed to 8.0.x. Thanks!

  • alexpott committed 8dbdbd7 on 8.0.x
    Issue #2412553 by amateescu: Taxonomy terms in an Entity Reference field...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

DuaelFr’s picture

There is an open discussion about that setting in #2372225-13: Add sort setting for taxonomy term autocomplete results