You are here

protected function MenuTreeStorage::loadLinks in Multiversion 8

Same name and namespace in other branches
  1. 8.2 src/MenuTreeStorage.php \Drupal\multiversion\MenuTreeStorage::loadLinks()

Loads links in the given menu, according to the given tree parameters.

Parameters

string $menu_name: A menu name.

\Drupal\Core\Menu\MenuTreeParameters $parameters: The parameters to determine which menu links to be loaded into a tree. This method will set the absolute minimum depth, which is used in MenuTreeStorage::doBuildTreeData().

Return value

array A flat array of menu links that are part of the menu. Each array element is an associative array of information about the menu link, containing the fields from the {menu_tree} table. This array must be ordered depth-first.

Overrides MenuTreeStorage::loadLinks

File

src/MenuTreeStorage.php, line 44

Class

MenuTreeStorage

Namespace

Drupal\multiversion

Code

protected function loadLinks($menu_name, MenuTreeParameters $parameters) {
  $links = parent::loadLinks($menu_name, $parameters);

  // Return links if the menu_link_content is not enabled.
  if (!\Drupal::moduleHandler()
    ->moduleExists('menu_link_content')) {
    return $links;
  }
  $map = [];

  // Collect all menu_link_content IDs from the links.
  foreach ($links as $i => $link) {
    if ($link['provider'] != 'menu_link_content') {
      continue;
    }
    $metadata = unserialize($link['metadata']);
    $map[$metadata['entity_id']] = $i;
  }

  // Load all menu_link_content entities and remove links for the those that
  // don't belong to the active workspace.
  $entities = $this->entityTypeManager
    ->getStorage('menu_link_content')
    ->loadMultiple(array_keys($map));
  foreach ($map as $entity_id => $link_id) {
    if (!isset($entities[$entity_id])) {
      unset($links[$link_id]);
    }
  }
  return $links;
}