function MenuParentFormSelector::getMenuOptions

Same name in other branches
  1. 9 core/lib/Drupal/Core/Menu/MenuParentFormSelector.php \Drupal\Core\Menu\MenuParentFormSelector::getMenuOptions()
  2. 8.9.x core/lib/Drupal/Core/Menu/MenuParentFormSelector.php \Drupal\Core\Menu\MenuParentFormSelector::getMenuOptions()
  3. 10 core/lib/Drupal/Core/Menu/MenuParentFormSelector.php \Drupal\Core\Menu\MenuParentFormSelector::getMenuOptions()

Gets a list of menu names for use as options.

Parameters

array $menu_names: (optional) Array of menu names to limit the options, or NULL to load all.

Return value

array Keys are menu names (ids) values are the menu labels.

1 call to MenuParentFormSelector::getMenuOptions()
MenuParentFormSelector::getParentSelectOptions in core/lib/Drupal/Core/Menu/MenuParentFormSelector.php
Gets the options for a select element to choose a menu and parent.

File

core/lib/Drupal/Core/Menu/MenuParentFormSelector.php, line 184

Class

MenuParentFormSelector
Default implementation of the menu parent form selector service.

Namespace

Drupal\Core\Menu

Code

protected function getMenuOptions(?array $menu_names = NULL) {
    $menus = $this->entityTypeManager
        ->getStorage('menu')
        ->loadMultiple($menu_names);
    $options = [];
    
    /** @var \Drupal\system\MenuInterface[] $menus */
    foreach ($menus as $menu) {
        $options[$menu->id()] = $menu->label();
    }
    return $options;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.