I would like to add an option (select) to a menu. I am using hook_form_menu_edit_form_alter to add a select element and an additional submit function. The select is shown and my submit function is called.

I don't know how to save the value and how to retrieve it. In my submit function I can get the menu entity by

$menu = $form_state->getFormObject()->getEntity();

But I can't find anything similar to options like for the single menu links.

  • Use Menu Item Extras module – Hudri Nov 8 at 19:15
  • To save a form value is something like: $this->config('module_name.module_name_settings')->set('module_setting', $values['module_setting'])->save();, to get the values in .module is something like: $config = \Drupal::config('module_name.module_name_settings'); Are your needs that specific, or more general? – Prestosaurus Nov 8 at 21:19
  • I know how to save the value in an own config. But I was rather searching for a possibility to store it 'correctly' with the menu, by kind of extending the menu. – Tobias Nov 9 at 9:27

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.