Problem/Motivation
MenuLinkTreeInterface::load() does not do any sorting or access checks, as might be expected. This should be better documented.
When loading a menu, for example using:
$tree = \Drupal::menuTree()->load('menu', new MenuTreeParameters());
the subtrees is not necessarily sorted by weight. For the subtrees to be sorted by weight we need to do something like:
$tree = \Drupal::menuTree()->load('menu', new MenuTreeParameters());
foreach ($tree as $key => $item) {
usort($tree[$key]['subtree'], function($a, $b) {
if ($a->link->getWeight() == $b->link->getWeight()) {
return 0;
}
return ($a->link->getWeight() < $b->link->getWeight()) ? -1 : 1;
});
}
This is unwieldy for developers, and the problem is compounded by the fact that the subtree _can_ be sorted, but is not necessarily, so if a subtree is sorted during development, it is easy to overlook this requirement.
Proposed resolution
Improve documentation.
Remaining tasks
Finalize documentation improvement.
User interface changes
None.
Introduced terminology
None.
API changes
None.
Data model changes
None.
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | 3015631-nr-bot.txt | 797 bytes | needs-review-queue-bot |
Issue fork drupal-3015631
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:
- 11.x
compare
- 3015631-when-loading-menu
changes, plain diff MR !9531
Comments
Comment #3
batkorHi!
thing close this issues
method transform
Comment #10
imclean commented#3 is the solution.
Comment #11
liam morlandThis should be better documented.
Comment #13
liam morlandComment #14
liam morlandComment #15
smustgrave commentedFor good practice should have a complete issue summary, using the standard template.
Comment #16
liam morlandComment #17
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #18
liam morlandRebased. Spell check passes.
Comment #19
smustgrave commentedBelieve this is an improvement.
Comment #20
amateescu commentedAdded a comment to the MR.
Comment #21
liam morlandFixed
Comment #22
amateescu commentedThanks!
Comment #23
quietone commentedUpdate credit
Comment #26
larowlanCommitted to 11.x and backported to 11.1.x.