Problem/Motivation

When a field uses the All predefined languages range together with the Custom languages range, the option list is not fully sorted alphabetically.

In CustomLanguageManager::allowedValues() each language subset is processed independently and only the predefined subset is sorted (via asort()). Every subset is then merged with $languages += $subsettable_languages;, so the custom languages get appended to the bottom of the list in the order they happen to be loaded, rather than in their correct alphabetical position among the predefined languages.

As a result, any newly added custom language shows up at the end of the select list instead of where it alphabetically belongs.

Steps to reproduce

1. Add a Language field to any entity type.
2. In the field storage settings, enable both All predefined languages and Custom languages.
3. Add a custom language.
4. Edit an entity with that field and open the language select widget.
5. Observe that the custom language(s) appear at the very bottom of the list rather than in alphabetical order.

Proposed resolution

Sort the complete merged list of allowed languages alphabetically by display name, instead of relying on per-subset sorting. This keeps predefined and custom languages interleaved in the correct alphabetical order.

Command icon 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

leoenriquezp created an issue. See original summary.

leoenriquezp’s picture

Status: Active » Needs review

The merge request is ready for review

  • johnv committed fcf0281e on 8.x-1.x
    Issue #3611214: Custom languages are not sorted properly
    
johnv’s picture

Title: Custom languages are appended to the bottom of the allowed values list instead of being sorted alphabetically » Custom languages not sorted properly, but appended to the bottom of the allowed values list
Status: Needs review » Fixed

Thanks, committed.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.