You are here

protected function DomainMenuLinkTreeManipulators::loadMenuLinkContentEntity in Domain Menu Access 8

Load menu link content from menu link entry.

Parameters

\Drupal\Core\Menu\MenuLinkInterface $instance: The menu link instance.

Return value

\Drupal\menu_link_content\Entity\MenuLinkContent The menu link entity.

1 call to DomainMenuLinkTreeManipulators::loadMenuLinkContentEntity()
DomainMenuLinkTreeManipulators::menuLinkCheckAccess in src/Menu/DomainMenuLinkTreeManipulators.php
Checks access for one menu link instance.

File

src/Menu/DomainMenuLinkTreeManipulators.php, line 168

Class

DomainMenuLinkTreeManipulators
Provides a couple of menu link tree manipulators.

Namespace

Drupal\domain_menu_access\Menu

Code

protected function loadMenuLinkContentEntity(MenuLinkInterface $instance) {
  $storage = $this->entityTypeManager
    ->getStorage('menu_link_content');
  $entity = NULL;
  if (!empty($instance
    ->getPluginDefinition()['metadata']['entity_id'])) {
    $entity_id = $instance
      ->getPluginDefinition()['metadata']['entity_id'];

    // Make sure the current ID is in the list, since each plugin empties
    // the list after calling loadMultiple(). Note that the list may include
    // multiple IDs added earlier in each plugin's constructor.
    static::$entityIdsToLoad[$entity_id] = $entity_id;
    $entities = $storage
      ->loadMultiple(array_values(static::$entityIdsToLoad));
    $entity = isset($entities[$entity_id]) ? $entities[$entity_id] : NULL;
    static::$entityIdsToLoad = [];
  }
  if (!$entity) {

    // Fallback to the loading by the UUID.
    if ($uuid = $instance
      ->getDerivativeId()) {
      $loaded_entities = $storage
        ->loadByProperties([
        'uuid' => $uuid,
      ]);
      $entity = reset($loaded_entities);
    }
  }
  return $entity;
}