You are here

public function CshsMenuParentFormSelector::getParentSelectOptionsCshs in Menu Link Weight 8

Same name and namespace in other branches
  1. 8.2 src/MenuParentFormSelector/CshsMenuParentFormSelector.php \Drupal\menu_link_weight\MenuParentFormSelector\CshsMenuParentFormSelector::getParentSelectOptionsCshs()
1 call to CshsMenuParentFormSelector::getParentSelectOptionsCshs()
CshsMenuParentFormSelector::parentSelectElement in src/MenuParentFormSelector/CshsMenuParentFormSelector.php
Gets a form element to choose a menu and parent.

File

src/MenuParentFormSelector/CshsMenuParentFormSelector.php, line 19

Class

CshsMenuParentFormSelector
Implements Client-side hierarchical select (CSHS) as the menu parent form selector.

Namespace

Drupal\menu_link_weight\MenuParentFormSelector

Code

public function getParentSelectOptionsCshs($id = '', array $menus = NULL, CacheableMetadata &$cacheability = NULL) {
  if (!isset($menus)) {
    $menus = $this
      ->getMenuOptions();
  }
  $options = [];
  $depth_limit = $this
    ->getParentDepthLimit($id);
  foreach ($menus as $menu_name => $menu_title) {
    $options[$menu_name . ':'] = [
      'name' => '<' . $menu_title . '>',
      'parent_tid' => 0,
    ];
    $parameters = new MenuTreeParameters();
    $parameters
      ->setMaxDepth($depth_limit);
    $tree = $this->menuLinkTree
      ->load($menu_name, $parameters);
    $manipulators = [
      [
        'callable' => 'menu.default_tree_manipulators:checkNodeAccess',
      ],
      [
        'callable' => 'menu.default_tree_manipulators:checkAccess',
      ],
      [
        'callable' => 'menu.default_tree_manipulators:generateIndexAndSort',
      ],
    ];
    $tree = $this->menuLinkTree
      ->transform($tree, $manipulators);
    $this
      ->parentSelectOptionsTreeWalkCshs($tree, $menu_name, $menu_name . ':', $options, $id, $depth_limit, $cacheability);
  }
  return $options;
}