1
2
3
// Format and add main menu to theme.
$menu = \Drupal::menuTree()->load('main', new MenuTreeParameters());
$variables['main_menu'] = \Drupal::menuTree()->build($menu);