You are here

protected function MenuLinkTreeManipulators::getLinkEntity in Menu Manipulator 8.2

Same name and namespace in other branches
  1. 3.0.x src/Menu/MenuLinkTreeManipulators.php \Drupal\menu_manipulator\Menu\MenuLinkTreeManipulators::getLinkEntity()
  2. 2.0.x src/Menu/MenuLinkTreeManipulators.php \Drupal\menu_manipulator\Menu\MenuLinkTreeManipulators::getLinkEntity()

Get targeted entity for a given MenuLinkContent.

Parameters

\Drupal\menu_link_content\Plugin\Menu\MenuLinkContent $link: `The Menu Link Content entity.

Return value

\Drupal\Core\Entity\EntityInterface|null|bool FALSE if Url is unrouted or an entity object variant or NULL if the entity does not exist.

1 call to MenuLinkTreeManipulators::getLinkEntity()
MenuLinkTreeManipulators::filterByCurrentLanguage in src/Menu/MenuLinkTreeManipulators.php
Filter a menu tree by current language MenuLinks.

File

src/Menu/MenuLinkTreeManipulators.php, line 183

Class

MenuLinkTreeManipulators
Provides a couple of menu link tree manipulators.

Namespace

Drupal\menu_manipulator\Menu

Code

protected function getLinkEntity(MenuLinkContent $link) {
  $metadata = $link
    ->getMetaData();
  $loaded_link = $this->menuLinkContentStorage
    ->load($metadata['entity_id']);
  $url = Url::fromUri($loaded_link
    ->get('link')
    ->getString());
  if (!$url instanceof Url || !$url
    ->isRouted()) {
    return FALSE;
  }

  // Get entity info from route.
  list($entity_type, $entity_id) = explode('/', $url
    ->getInternalPath());
  return !\is_string($entity_type) || empty($entity_id) ? FALSE : $this->entityRepository
    ->getActive($entity_type, $entity_id);
}