How to write custom menu link tree manipulator
In this post, I will show you how to write custom menu link tree manipulator.
In Drupal 9/10, we can write a custom menu link tree manipulator. For example, If you want to load the menu link tree sorted. The Drupal core provides the \Drupal\Core\Menu\DefaultMenuLinkTreeManipulators::generateIndexAndSort. This manipulator loads the sorted menu link tree as nested array but the keys of array also have the index.
In this blog I am going to write a custom manipulator that will return the menu link tree sorted by menu link weight and maintain the array key as menu link plugin id.