MenuParentFormSelector::getParentSelectOptions

public MenuParentFormSelector::getParentSelectOptions($id = '', array $menus = NULL, CacheableMetadata &$cacheability = NULL)

Gets the options for a select element to choose a menu and parent.

Parameters

string $id: Optional ID of a link plugin. This will exclude the link and its children from the select options.

array $menus: Optional array of menu names as keys and titles as values to limit the select options. If NULL, all menus will be included.

\Drupal\Core\Cache\CacheableMetadata|null &$cacheability: Optional cacheability metadata object, which will be populated based on the accessibility of the links and the cacheability of the links.

Return value

array Keyed array where the keys are contain a menu name and parent ID and the values are a menu name or link title indented by depth.

Overrides MenuParentFormSelectorInterface::getParentSelectOptions

File

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

Class

MenuParentFormSelector
Default implementation of the menu parent form selector service.

Namespace

Drupal\Core\Menu

Code

public function getParentSelectOptions($id = '', array $menus = NULL, CacheableMetadata &$cacheability = NULL) {
  if (!isset($menus)) {
    $menus = $this->getMenuOptions();
  }

  $options = array();
  $depth_limit = $this->getParentDepthLimit($id);
  foreach ($menus as $menu_name => $menu_title) {
    $options[$menu_name . ':'] = '<' . $menu_title . '>';

    $parameters = new MenuTreeParameters();
    $parameters->setMaxDepth($depth_limit);
    $tree = $this->menuLinkTree->load($menu_name, $parameters);
    $manipulators = array(
      array('callable' => 'menu.default_tree_manipulators:checkNodeAccess'),
      array('callable' => 'menu.default_tree_manipulators:checkAccess'),
      array('callable' => 'menu.default_tree_manipulators:generateIndexAndSort'),
    );
    $tree = $this->menuLinkTree->transform($tree, $manipulators);
    $this->parentSelectOptionsTreeWalk($tree, $menu_name, '--', $options, $id, $depth_limit, $cacheability);
  }
  return $options;
}
doc_Drupal
2016-10-29 09:27:26
Comments
Leave a Comment

Please login to continue.