You are here

public function MenuLinkTreeHandler::getMenuLinkItemEntity in Menu Item Extras 8.2

Get menu_link_content entity.

Parameters

\Drupal\Core\Menu\MenuLinkInterface $link: Link object.

Return value

\Drupal\menu_link_content\MenuLinkContentInterface|null Menu Link Content entity.

Overrides MenuLinkTreeHandlerInterface::getMenuLinkItemEntity

3 calls to MenuLinkTreeHandler::getMenuLinkItemEntity()
MenuLinkTreeHandler::getMenuLinkItemViewMode in src/Service/MenuLinkTreeHandler.php
Get Menu Link Item view mdoe.
MenuLinkTreeHandler::isMenuLinkDisplayedChildren in src/Service/MenuLinkTreeHandler.php
Checks if Menu Link Children is enabled to display.
MenuLinkTreeHandler::processMenuLinkTree in src/Service/MenuLinkTreeHandler.php
Process menu tree items. Add menu item content.

File

src/Service/MenuLinkTreeHandler.php, line 46

Class

MenuLinkTreeHandler
Class MenuLinkTreeHandler.

Namespace

Drupal\menu_item_extras\Service

Code

public function getMenuLinkItemEntity(MenuLinkInterface $link) {
  $menu_item = NULL;
  $metadata = $link
    ->getMetaData();
  if (!empty($metadata['entity_id'])) {

    /** @var \Drupal\menu_link_content\Entity\MenuLinkContent $menu_item */
    $menu_item = $this->entityTypeManager
      ->getStorage('menu_link_content')
      ->load($metadata['entity_id']);
  }
  else {
    $menu_item = $this->entityTypeManager
      ->getStorage('menu_link_content')
      ->create($link
      ->getPluginDefinition());
  }
  if ($menu_item) {
    $menu_item = $this->entityRepository
      ->getTranslationFromContext($menu_item);
  }
  return $menu_item;
}