Skip to content

Instantly share code, notes, and snippets.

@rpayanm
Created July 12, 2019 20:24
Show Gist options
  • Save rpayanm/4f5e744ad83e72b52bce40f0199dde34 to your computer and use it in GitHub Desktop.
Save rpayanm/4f5e744ad83e72b52bce40f0199dde34 to your computer and use it in GitHub Desktop.
<?php
// LOAD
// You can load up the menu tree with MenuLinkTree::load, which will give you an array of menu links to work with. From there it's just a matter of looping through and getting what you need, e.g.
$tree = \Drupal::menuTree()->load('main', new \Drupal\Core\Menu\MenuTreeParameters());
foreach ($tree as $item) {
$title = $item->link->getTitle();
$url_obj = $item->link->getUrlObject();
$has_children = $item->hasChildren;
// etc...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment