protected function MenuLinkTreeManipulators::getLinkEntity in Menu Manipulator 2.0.x
Same name and namespace in other branches
- 8.2 src/Menu/MenuLinkTreeManipulators.php \Drupal\menu_manipulator\Menu\MenuLinkTreeManipulators::getLinkEntity()
- 3.0.x src/Menu/MenuLinkTreeManipulators.php \Drupal\menu_manipulator\Menu\MenuLinkTreeManipulators::getLinkEntity()
Get targeted entity for a given MenuLinkBase.
Parameters
\Drupal\Core\Menu\MenuLinkBase $link: `The Menu Link Content entity.
Return value
\Drupal\Core\Entity\EntityInterface|null|bool FALSE if Url is unrouted. Otherwise, an entity object variant or NULL.
1 call to MenuLinkTreeManipulators::getLinkEntity()
File
- src/
Menu/ MenuLinkTreeManipulators.php, line 155
Class
- MenuLinkTreeManipulators
- Provides a menu link tree manipulators.
Namespace
Drupal\menu_manipulator\MenuCode
protected function getLinkEntity(MenuLinkBase $link) {
$metadata = $link
->getMetaData();
if (!isset($metadata['entity_id'])) {
return NULL;
}
$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.
$parts = explode('/', $url
->getInternalPath());
if (empty($parts[0] ?? '') || empty($parts[1] ?? '')) {
return FALSE;
}
$entity_type = $parts[0];
$entity_id = $parts[1];
return !\is_string($entity_type) || empty($entity_id) ? FALSE : $this->entityRepository
->getActive($entity_type, $entity_id);
}