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;
}
doc_Drupal
2016-10-29 09:27:37
Comments
Leave a Comment

Please login to continue.