You are here

protected function ContentEntityNormalizer::getMenuLinkNodeAttached in Content Synchronization 8.2

Same name and namespace in other branches
  1. 3.0.x src/Normalizer/ContentEntityNormalizer.php \Drupal\content_sync\Normalizer\ContentEntityNormalizer::getMenuLinkNodeAttached()

Gets a node attached to a menu link. The node has already been imported.

Parameters

\Drupal\menu_link_content\Entity\MenuLinkContent $object: Menu Link Entity.

Return value

\Drupal\Core\Entity\EntityInterface|null Node Entity.

1 call to ContentEntityNormalizer::getMenuLinkNodeAttached()
ContentEntityNormalizer::normalize in src/Normalizer/ContentEntityNormalizer.php
Normalizes an object into a set of arrays/scalars.

File

src/Normalizer/ContentEntityNormalizer.php, line 190

Class

ContentEntityNormalizer
Adds the file URI to embedded file entities.

Namespace

Drupal\content_sync\Normalizer

Code

protected function getMenuLinkNodeAttached(MenuLinkContent $object) {
  $uri = $object
    ->get('link')
    ->getString();
  $url = Url::fromUri($uri);
  try {
    $route_parameters = $url
      ->getRouteParameters();
    if (count($route_parameters) == 1) {
      $entity_id = reset($route_parameters);
      $entity_type = key($route_parameters);
      return \Drupal::entityTypeManager()
        ->getStorage($entity_type)
        ->load($entity_id);
    }
  } catch (\Exception $e) {

    // If menu link is linked to a non-node page - just do nothing.
  }
}