Returns a list of menu links that are valid possible parents for the given menu link.
@todo This has to be turned into a #process form element callback. The 'override_parent_selector' variable is entirely superfluous.
array $menus: An array of menu names and titles, such as from menu_get_menus().
\Drupal\menu_link\Plugin\Core\Entity\MenuLink $menu_link: The menu link for which to generate a list of parents. If $menu_link->id() == 0 then the complete tree is returned.
string $type: The node type for which to generate a list of parents. If $item itself is a node type then $type is ignored.
array An array of menu link titles keyed by a string containing the menu name and mlid. The list excludes the given item and its children.
function menu_parent_options(array $menus, MenuLink $menu_link = NULL, $type = NULL) {
// The menu_links table can be practically any size and we need a way to
// allow contrib modules to provide more scalable pattern choosers.
// hook_form_alter is too late in itself because all the possible parents are
// retrieved here, unless override_parent_selector is set to TRUE.
if (config('menu.settings')
->get('override_parent_selector')) {
return array();
}
if (!$menu_link) {
$menu_link = entity_create('menu_link', array(
'mlid' => 0,
));
}
$available_menus = array();
if (!$type) {
// If no node type is set, use all menus given to this function.
$available_menus = $menus;
}
else {
// If a node type is set, use all available menus for this type.
$type_menus = variable_get('menu_options_' . $type, array(
'main' => 'main',
));
foreach ($type_menus as $menu) {
$available_menus[$menu] = $menu;
}
}
return _menu_get_options($menus, $available_menus, $menu_link);
}