Menu machine names - additional validation - prevent mistakes

Created on 12 April 2024, 5 months ago
Updated 24 April 2024, 5 months ago

Problem/Motivation

When you create a menu, you can add spaces or uppercase letters to the machine name and the menu will be created.

Steps to reproduce

1. Go the Menus, and click on Add menu,
2. Set the title and you will see the machine name proposed,
3. Click on Edit (to edit the machine name),
4. Add spaces or uppercase letters to the new machine name,
5. Save and the new menu will be created.

6. Go back to the Menu list and the menu will be there.

Illustrations:

when "dummies do this", lots of lots of errors and a messy cleanup is required.

Dummy step 1)

  • From /admin/structure/menu/add enter a menu title

Illustration of Dummy step 1:

Dummy step 2)

  • press the edit link for machine name, manually replace the underscores with spaces.

Illustration of Dummy step 2:

Dummy step 3)

  • Press save

The result is a mess that needs a database restore from backup or some tricky work outside of the drupal api to clean it up.

Suggested solution:

  • Add submit validation handling for these machine names to prevent dummies from breaking stuff.

Proposed resolution

You should not be able to create a new menu if the machine name dont fill the requirements.

🐛 Bug report
Status

Closed: works as designed

Version

11.0 🔥

Component
Menu system 

Last updated 1 day ago

Created by

🇨🇦Canada jcninov

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

Comments & Activities

  • Issue created by @jcninov
  • First commit to issue fork.
  • Status changed to Needs review 5 months ago
  • 🇮🇳India Anandt846

    It seems that the issue you mentioned, not exist or some key information is missing in the description. Attaching the screen shot -

    In ordered to replicate - I tried various combinations including and excluding uppercase, integers, lowercase and spaces. I had encountered error when expected and no unexpected error encountered. To demonstrate, I attached a particular screenshot containing a machine name appended with one space.

  • Status changed to Postponed: needs info 5 months ago
  • 🇺🇸United States smustgrave

    @jcninov can you provide additional information

  • 🇨🇦Canada jcninov

    Hi, thanks for the answer.

    Just after click on Save, you have the error message but if you go to the menu list, the menu will be there.
    I add another step, just after 5 Click on save.

    6. Go back to the Menu list and the menu will be there.

  • Status changed to Active 5 months ago
  • 🇨🇦Canada joseph.olstad

    So what happens is, when "dummies do this", lots of lots of errors and a messy cleanup is required.

    Dummy step 1)

    • Enter a menu title

    Illustration of Dummy step 1:

    Dummy step 2)

    • press the edit link for machine name, manually replace the underscores with spaces.

    Illustration of Dummy step 2:

    Dummy step 3)

    • Press save

    The result is a mess that needs a database restore from backup or some tricky work outside of the drupal api to clean it up.

    Suggested solution:

    Add submit validation handling for these machine names to prevent dummies from breaking stuff.

  • Status changed to Needs work 5 months ago
  • 🇨🇦Canada joseph.olstad

    @smustgrave , or anyone else?
    Would it be possible/feasible to create a constraint plugin for the machine_name value of the menu entity (or other entity types?)

    https://www.drupal.org/docs/drupal-apis/entity-api/entity-validation-api...

    I saw a field constraint get added to one of my custom projects but what about for a machine_name on an entity type? is this type of constraint possible with the plugin system?

  • Status changed to Closed: works as designed 5 months ago
  • 🇨🇦Canada joseph.olstad

    This is fixed in D10.3.0

  • 🇨🇦Canada joseph.olstad

    actually , I also tested Drupal 9.5.11 and I was unable to save a space, thankfully.

Production build 0.71.5 2024