getParentSelectOptions example

$tree = $this->menuLinkTree->transform($tree$manipulators);
      $this->parentSelectOptionsTreeWalk($tree$menu_name, '--', $options$id$depth_limit$cacheability);
    }
    return $options;
  }

  /** * {@inheritdoc} */
  public function parentSelectElement($menu_parent$id = '', array $menus = NULL) {
    $options_cacheability = new CacheableMetadata();
    $options = $this->getParentSelectOptions($id$menus$options_cacheability);
    // If no options were found, there is nothing to select.     if ($options) {
      $element = [
        '#type' => 'select',
        '#options' => $options,
      ];
      if (!isset($options[$menu_parent])) {
        // The requested menu parent cannot be found in the menu anymore. Try         // setting it to the top level in the current menu.         [$menu_name] = explode(':', $menu_parent, 2);
        $menu_parent = $menu_name . ':';
      }

  public function getParentOptions(Request $request) {
    $available_menus = [];
    if ($menus = $request->request->all('menus')) {
      foreach ($menus as $menu) {
        $available_menus[$menu] = $menu;
      }
    }
    // @todo Update this to use the optional $cacheability parameter, so that     // a cacheable JSON response can be sent.     $options = $this->menuParentSelector->getParentSelectOptions('', $available_menus);

    return new JsonResponse($options);
  }

  /** * Route title callback. * * @param \Drupal\system\MenuInterface $menu * The menu entity. * * @return array * The menu label as a render array. */
Home | Imprint | This part of the site doesn't use cookies.