Show field on node edit page

Created on 11 August 2018, over 6 years ago
Updated 28 February 2024, 9 months ago

I expected that once I add a field to menu items they would show up in the node edit page "Menu" options. Or even better, this could be editable using the form-display tab.

Feature request
Status

Needs work

Version

2.0

Component

Code

Created by

🇨🇭Switzerland idflood

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States codechefmarc

    Came across this and GaëlG's worked great when there was a link set. If one was not set, it would cause errors. So, I modified one part of it:

    function MY_MODULE_save_menu_link_fields(array $form, FormStateInterface $form_state) {
      if ($link = _ys_core_get_link($form_state)) {
        // Only save the menu item extras if there is a menu link with a route.
        if ($link->getUrlObject()->getRouteName()) {
          $form_display = EntityFormDisplay::load('menu_link_content.' . $link->getMenuName() . '.default');
          assert($form_display instanceof EntityFormDisplay);
          $form_display->extractFormValues($link, $form['menu']['link']['extra'], $form_state);
          $link->save();
        }
      }
    }
    

    The change is the if ($link->getUrlObject()->getRouteName()) { which checks to see if there is an actual route in the link. If so, go ahead and save the menu item extras fields. If not, ignore it.

  • 🇺🇸United States slattery

    Thank you all. Thanks GaëlG and codechefmarc for #6 and #8. I got far with these!

    I needed to patch Plugin/Field/FieldWidget/MenuItemExtrasViewModeSelectorSelect.php to work with link view modes on node add and edit forms. The widget was picking up the node storage view modes rather than the menu_link_content view modes given to us by extras. This change seems to work in node forms and menu forms, hopefully others can confirm.

Production build 0.71.5 2024