Loading a menu tree and parsing the menu_tree_elements loading the menu_link_content entities is not straight forward. I have to perform it like this.
$menu_id = 'menu';
$menu_tree = \Drupal::menuTree();
$menu_parameters = $menu_tree->getCurrentRouteMenuTreeParameters($menu_id);
$menu_tree_elements = $menu_tree->load($menu_id, $menu_parameters);
foreach($menu_tree_elements as $menu_tree_element){
$id = $menu_tree_element->link->getMetaData()['entity_id'];
$menulink = \Drupal::entityTypeManager()->getStorage('menu_link_content')->load($id);
var_dump('Title: '. $menulink->label());
}
I notice that getEntity() is a method that does almost exactly what I'm already doing in order to get the menu_link_content, but it's a protected function. Why would they make that function protected? Is it because I'm doing things in a really round about way when I should be using a different method?