function MenuTreeStorage::findParent

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Menu/MenuTreeStorage.php \Drupal\Core\Menu\MenuTreeStorage::findParent()
  2. 10 core/lib/Drupal/Core/Menu/MenuTreeStorage.php \Drupal\Core\Menu\MenuTreeStorage::findParent()
  3. 11.x core/lib/Drupal/Core/Menu/MenuTreeStorage.php \Drupal\Core\Menu\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 580

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 = [];
    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.