protected function MenuTreeStorage::findParent

protected MenuTreeStorage::findParent($link, $original)

Loads the parent definition if it exists.

Parameters

array $link: The link definition to find the parent of.

array|false $original: The original link that might be used to find the parent if the parent is not set on the $link, or FALSE if the original could not be loaded.

Return value

array|false Returns a definition array, or FALSE if no parent was found.

File

core/lib/Drupal/Core/Menu/MenuTreeStorage.php, line 563

Class

MenuTreeStorage
Provides a menu tree storage using the database.

Namespace

Drupal\Core\Menu

Code

protected function findParent($link, $original) {
  $parent = FALSE;

  // This item is explicitly top-level, skip the rest of the parenting.
  if (isset($link['parent']) && empty($link['parent'])) {
    return $parent;
  }

  // If we have a parent link ID, try to use that.
  $candidates = array();
  if (isset($link['parent'])) {
    $candidates[] = $link['parent'];
  }
  elseif (!empty($original['parent']) && $link['menu_name'] == $original['menu_name']) {
    // Otherwise, fall back to the original parent.
    $candidates[] = $original['parent'];
  }

  foreach ($candidates as $id) {
    $parent = $this->loadFull($id);
    if ($parent) {
      break;
    }
  }
  return $parent;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Menu!MenuTreeStorage.php/function/MenuTreeStorage::findParent/8.1.x