Contextual links are not sorted by weight, contrary to documentation

Created on 29 November 2017, almost 7 years ago
Updated 10 April 2023, over 1 year ago

According to the documentation for hook_contextual_links_alter(), contextual links are sortable by weight. The core menu code correctly stores the weights of links, however the contextual module fails to actually perform the sort when generating the menu.

For example, if I have something like this in mymodule.links.contextual.yml:

entity.node.delete:
  route_name: entity.node.delete
  group: my_group
  title: Delete
  weight: 3

entity.node.edit_form:
  route_name: entity.node.edit_form
  group: my_group
  title: Edit
  weight: 2

entity.node.canonical:
  route_name: entity.node.canonical
  group: my_group
  title: Create
  weight: 1

the links should appear in the order Create, Edit, Delete. Instead, the current implementation simply uses the order the links are added to the array.

I am attaching a patch, but leaving this issue as "needs works", since there should probably be a test written. Before doing that, however, the relevant parties should probably weigh in as to whether this is the correct way to fix the problem.

πŸ› Bug report
Status

Fixed

Version

9.5

Component
ContextualΒ  β†’

Last updated 3 days ago

Created by

πŸ‡ΊπŸ‡ΈUnited States Gribnif

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024