You are here

protected function MenuLinkTreeManipulator::getEntity in Menu block current language 8

Load entity with given menu link.

Parameters

\Drupal\menu_link_content\Plugin\Menu\MenuLinkContent $link: The menu link.

Return value

bool|\Drupal\Core\Entity\EntityInterface|null Boolean if menu link has no metadata. NULL if entity not found and an EntityInterface if found.

1 call to MenuLinkTreeManipulator::getEntity()
MenuLinkTreeManipulator::filterLanguages in src/MenuLinkTreeManipulator.php
Filter out links that are not translated to the current language.

File

src/MenuLinkTreeManipulator.php, line 91

Class

MenuLinkTreeManipulator
A menu link tree manipulator.

Namespace

Drupal\menu_block_current_language

Code

protected function getEntity(MenuLinkContent $link) {

  // MenuLinkContent::getEntity() has protected visibility and cannot be used
  // to directly fetch the entity.
  $metadata = $link
    ->getMetaData();
  if (empty($metadata['entity_id'])) {
    return FALSE;
  }
  return $this->entityTypeManager
    ->getStorage('menu_link_content')
    ->load($metadata['entity_id']);
}