Menu link saved with invalid link_options data when using Menu Attributes module

Created on 26 January 2024, 5 months ago
Updated 25 April 2024, 2 months ago

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.

🐛 Bug report
Status

Needs review

Version

2.1

Component

Code

Created by

🇳🇿New Zealand hitfactory

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

Merge Requests

Comments & Activities

Production build 0.69.0 2024