Problem/Motivation

The default menu tree manipulator generateIndexAndSort should sort menu items by weight and then by title (alphabetically). However if two menu items have the same weight and a title starting with the same text, the item with the longer title typically is (incorrectly) sorted before the item with the shorter title.

The manipulator uses ksort to sort the menu items. The keys consist of a fixed prefix, the weight, name and plugin id of the menu item. The addition of the plugin id is required to ensure the keys are unique, however results in this incorrect sorting.

Steps to reproduce

Add two or more menu links to a menu with the same weight:

  • Menu link A
  • Menu link A (extra text)

Verify that the menu links are incorrectly sorted:

  • Menu link A (extra text)
  • Menu link A

Proposed resolution

Instead of using ksort() on a generated/composed key, simply use uasort().

CommentFileSizeAuthor
#2 3442053-2.patch1.56 KBcasey

Issue fork drupal-3442053

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

casey created an issue. See original summary.

casey’s picture

StatusFileSize
new1.56 KB
casey’s picture

Status: Active » Needs review

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Thank you for reporting.

As a next step will need a test case to show the issue.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.