0

I want to display the menu items in a select list.

$items = \Drupal::service('menu.parent_form_selector')->getParentSelectOptions('main:', ['main' => 'Main']);

It gives the following select list options.

array:7 [▼
  "main:" => "<Main>"
  "main:menu_link_content:e92098f4-98c8-47d7-9697-a00da00ff6ce" => "-- Menu item 1"
  "main:menu_link_content:4552ac61-8b04-4785-913f-9deb6eae6a1f" => "---- Menu item 1 child"
  "main:menu_link_content:1eb2237a-eb55-4225-bdd1-078bb9db799b" => "------ child of child "
  "main:menu_link_content:2d105a33-9405-428f-81da-04ff2e8fb2da" => "-- Menu item 2"
  "main:menu_link_content:7619a127-3b25-4480-be88-7cfa1280180d" => "---- Menu item 2 child 1"
  "main:menu_link_content:2b1c8d61-bf3f-4245-8bee-ae404e5be528" => "---- Menu item 2 child 2"
]

Which is correct. Now I want to display the children of a specific menu item in another select list. Suppose Menu item 1. How will I do this?

I tried this code:

$menu_parent_selector = \Drupal::service('menu.parent_form_selector')->getParentSelectOptions('main:menu_link_content:e92098f4-98c8-47d7-9697-a00da00ff6ce', ['main' => 'Main']);

But it gives me the same results. All the menu items of the main menu.

Is there any way to get the children of the Menu item 1 only in the same format?

array:2 [▼
      "main:menu_link_content:4552ac61-8b04-4785-913f-9deb6eae6a1f" => "---- Menu item 1 child"
      "main:menu_link_content:1eb2237a-eb55-4225-bdd1-078bb9db799b" => "------ child of child "
    ]

Is there any hint to build it custom if nothing is available?

1
  • there is no solution?
    – Ahmad
    Dec 22 '20 at 4:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.