function MenuTreeStorage::findParent
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.
1 call to MenuTreeStorage::findParent()
- MenuTreeStorage::preSave in core/
lib/ Drupal/ Core/ Menu/ MenuTreeStorage.php  - Fills in all the fields the database save needs, using the link definition.
 
File
- 
              core/
lib/ Drupal/ Core/ Menu/ MenuTreeStorage.php, line 559  
Class
- MenuTreeStorage
 - Provides a menu tree storage using the database.
 
Namespace
Drupal\Core\MenuCode
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 = [];
  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;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.