Problem/Motivation
This line in simple_megamenu_menu_link_content_form_submit can cause invalid data to be saved to the link_options column of the menu_link_content_data table if $menu_link_options already contains the 'data-simple-mega-menu' key in its 'attributes' array.
$menu_link->link->first()->options = array_merge_recursive($menu_link_options, $data_simple_mega_menu);
What happens is $menu_link->link->first()->options ends up being saved as
[
"attributes" => [
"data-simple-mega-menu" => [
0 => 1,
1 => 1,
]
]
The menu link will no longer be able to be edited and the frontend pages which include the megamenu will trigger an error and your site will become unavailable.
Steps to reproduce
We have seen this happen when using both the Simple Mega Menu and Menu Link Attributes modules.
Proposed resolution
The Menu Link Attributes module is not without its own bugs, but Simple Mega Menu should account for the fact that the above can happen and instead only overwrite the "data-simple-mega-menu" key in the attributes of the link options rather than the entire options array which can include attributes provided by other modules.
Remaining tasks
Merge request to come.
User interface changes
None
API changes
See merge request to come.
Data model changes
None.
Issue fork simple_megamenu-3417145
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
hitfactory commentedComment #9
flocondetoileComment #10
hitfactory commentedSorry for the clutter. I couldn't work out how to delete the merge request against the wrong branch and only figured out later I could change the branch without creating a new one.
To add a bit more context, this happens because the Attributes fieldset which displays via the Menu Link Attributes module may not always be visible to the end user if they don't have the ''use menu link attributes' permission.
When a user doesn't have the ''use menu link attributes' permission, then the $menu_link_options variable passed as the first argument to array_merge_recursive in simple_megamenu_menu_link_content_form_submit will be identical to the second argument $data_simple_mega_menu.
Comment #11
anybodyWe're running into the same issue now!
@hitfactory did you also test your MR works without the Menu Attributes module?
Code-wise I'd say it won't?
Comment #15
flocondetoileThanks. Committed