Class values in menu link submit hook are appended instead of replaced

Created on 4 May 2021, over 3 years ago
Updated 5 July 2023, over 1 year ago

Problem/Motivation

When having a value in the "class" attribute field, and saving a menu item, the value gets appended to the class array. This eventually leads to a "Class cannot be longer than 128 characters but is currently [X] characters long." message. In addition, it's not possible to remove previously submitted values.

Steps to reproduce

1. Add a value that is 65 or more characters long to the "class" field.
2. Save the menu item.
3. Save the menu item again without making any changes.
4. Validation error is displayed, and it's not longer possible to save.

Proposed resolution

Attached patch replace instead of append values to the class array.
Note that it may be that current logic is due to an edge case I'm not currently aware about.

Remaining tasks

There might be a need for an update hook to fix existing class field values. If one has got to the point where the validation error message appears, it's not no longer possible to save the menu item, and there is no way to fix this except for maybe deleting the field. Due to this, I would consider this a Major issue.

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ΈπŸ‡ͺSweden enzipher

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.

Production build 0.71.5 2024