public function MenuLinkTreeHandler::getMenuLinkItemContent in Menu Item Extras 8.2
Get Menu Link Content entity content.
Parameters
\Drupal\menu_link_content\MenuLinkContentInterface $link: Original link entity.
Return value
array Renderable menu item content.
Overrides MenuLinkTreeHandlerInterface::getMenuLinkItemContent
1 call to MenuLinkTreeHandler::getMenuLinkItemContent()
- MenuLinkTreeHandler::processMenuLinkTree in src/
Service/ MenuLinkTreeHandler.php - Process menu tree items. Add menu item content.
File
- src/
Service/ MenuLinkTreeHandler.php, line 83
Class
- MenuLinkTreeHandler
- Class MenuLinkTreeHandler.
Namespace
Drupal\menu_item_extras\ServiceCode
public function getMenuLinkItemContent(MenuLinkContentInterface $entity, $menu_level = NULL, $show_item_link = FALSE) {
// Build the render array for this menu link.
$view_builder = $this->entityTypeManager
->getViewBuilder('menu_link_content');
$view_mode = $entity
->id() ? $this
->getMenuLinkContentViewMode($entity) : 'default';
$render_output = $view_builder
->view($entity, $view_mode);
// Build the entity view ourselves and unset the #pre_render so that it
// doesn't run twice later on, when rendered.
// This gives us access to all fields immediately in the menu template.
$render_output = $view_builder
->build($render_output);
array_pop($render_output['#pre_render']);
// Unset cache, handled by menu_item_extras_link_item_content_active_trails.
unset($render_output['#cache']);
// Add other properties.
$render_output['#show_item_link'] = $show_item_link;
if (!is_null($menu_level)) {
$render_output['#menu_level'] = $menu_level;
}
return $render_output;
}