- 🇺🇸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.