Problem/Motivation
I named my custom menus starting with a * to distinguish them from the system menus e.g:
*Navigation Left
*Navigation Middle
*Navigation Right
The machine names are like that:
-navigation-left
-navigation-middle
-navigation-right
Menus are not rendered because the corresponding theme hook becomes like menu___name. The ThemeManager::render() searches for hook implementation by stripping double underscores. In this case it fails to find it because the hook name contains triple underscore.
https://git.drupalcode.org/project/drupal/blob/8.8.2/core/lib/Drupal/Cor...
Steps to reproduce
- Create a new menu in /admin/structure/menu
- title: *Left Navigation
- Add a menu link to this menu (no matter to where this link is)
- Create another new menu in /admin/structure/menu (to show the difference)
- title: Right navigation
- Add a menu link to this menu (no matter to where this link is)
- Go to /admin/structure/block to place both menus in your main menu
- Place the Primary Menu Block and select the first menu ( *Left Navigation ) and save it
- Place the Primary Menu Block and select the second menu (Right Navigation) and save it
- Now go to your homepage, you will notice that Right Navigation was created with the link, while *Left Navigation was not
Proposed resolution
Prevent menu names from starting with a leading -
Remaining tasks
Patch review
User interface changes
Before patch is applied:

After patch applied:

Comments
Comment #2
chi commentedComment #6
larowlanComment #7
hmendes commentedI can see that this problem is happening on Drupal 9.5.x, updating the IS with the steps to reproduce.
Comment #8
hmendes commentedComment #9
hmendes commentedFirst try at this issue following the Proposed resolution.
Please review.
Comment #10
ranjith_kumar_k_u commentedCS fixes
Comment #11
ranjith_kumar_k_u commentedCspell fix
Comment #12
asha nair commentedApplied patch #11 successfully. Now, will get error when menu starts with special characters
Comment #13
asha nair commentedAdding screenshots
Comment #14
hmendes commentedThanks @ranjith_kumar_k_u for fixing the problems :D
@Asha Nair, did you tested it and did a code review?
Can you change this to RTBC if it is all right?
Comment #15
jobsons commentedHi, after applying @ranjith_kumar_k_u #11 patch, I did the code review of the issue and manually tested the following charachters with the beginning of the title:
~ ,
` ,
! ,
@ ,
# ,
$ ,
% ,
^ ,
& ,
* ,
( ,
) ,
_ ,
- ,
+ ,
= ,
{ ,
[ ,
} ,
] ,
| ,
\ ,
: ,
; ,
" ,
' ,
< ,
, ,
> ,
. ,
? ,
/ .
All of them led to the Error message: The title can not begin with special characters.
For this reason, I'm changing the status of the issue to RTBC.
Comment #16
catchMenus are entities, so I think this should be handled via an entity validation constraint instead of in the form.
Comment #17
michelecris commentedHi!
I will try to work on that.
thanks!
Comment #18
paulocsHello @catch, Menu is a config entity as we can see in
Drupal\system\Entity\Menu.Should we really use entity validation constraint for it? If yes, do you have any example how to implement it for config entities? All examples I see in core are used for content entities only.
I have also noticed that other config entities use the
validateForm()to check the field values like inDrupal\node\NodeTypeFormComment #19
michelecris commentedHi!
Sorry, I really try to work on this validation, but I couldn't make it run. So I'm unassigned here.
Comment #20
paulocsI have updated the patch based on the suggestion from @catch in #16.
Comment #21
vinmayiswamy commentedI applied #20 patch against 9.5.x-dev. Patch applied cleanly but I'm not able add menu link with special character after applying patch.
Attaching screenshots for reference.
Thanks
Edit: Apologies for not posting my review clearly. I meant that the patch I tested preventing the menus which are having special characters. So patch working as expected.
Thanks for the patch @paulocs
Comment #22
paulocsBut that's the idea of the issue, isn't it?
Comment #23
anjali rathodThe patch applied successfully and works as required.
Moving this ticket to RTBC.
Thanks!
Comment #24
quietone commentedAlmost there, a few more things to do.
I've only skimmed the comments but I see that the code has not been reviewed. Setting to NW.
Since this is changing validation of user input there should be before and after screenshots in the issue summary.
Comment #25
paulocsUploading screenshots and updating IS.
Comment #26
smustgrave commentedDon't see a tests-only patch if we can get that please.
Comment #27
paulocsComment #28
lucasscComment #29
lucasscCode looks good!
For ../core/modules/menu_ui/tests/src/Functional/MenuUiTest::testMenuName, maybe we don't need to assign $page in this line?
$page = $this->getSession()->getPage();This is not used afterwards.
Adding patch #29 and interdiff for the consideration above in case it makes sense.
Comment #30
Manibharathi E R commentedPatch #29 Tested and Applied successfully on Drupal 9.5.x.
Before Patch:
After Patch:
Comment #31
charchil khandelwal commented#29 Patch is working fine and shared the screenshot for the reference.
Comment #32
heni_deepak commented#29 looks like working and green.
need to reviewed by community.
Comment #34
lucasscI think it was a random fail of ckeditor5.
Thanks for the reviews @Manibharathi E R, @Charchil Khandelwal and @heni_deepak.
Patch works, but we still need a core review as @quietone said in #24:
Comment #35
heni_deepak commentedYes, @lucassc the error coming form based class
trait TestFileCreationTrait { }and mean code is
$this->getTestFiles('image')[0]->urithat function need to update as per parent function.
I found this #3231694: TestFileCreationTrait::getTestFiles() has incorrect @return type
Comment #36
heni_deepak commentedLooks like #3231694: TestFileCreationTrait::getTestFiles() has incorrect @return type fixed and #29 patch also works.
Comment #37
alexpottThis is related to #2920678: Add config validation for the allowed characters of machine names and #2869792: [meta] Add constraints to all config entity types
I feel that we should be able to call validate on config entities much the same way we can on content entities - that way we wouldn't need to have so much in the MenuForm class.
If we do do this we'll need to make the argument optional and issue a deprecation.
Comment #38
ghost of drupal pastI am not sure about this. I would guess it is possible with current code to fix the suggestions in an appropriate alter hook and so maybe people can have menus which will break on import after this? Is there a reason beyond the theme suggestion to disallow them? If not, then maybe fix that code?
Comment #41
quietone commentedI tested this on 11.x, fresh standard install, today and was not able to reproduce the problem using the steps in the Issue Summary. Therefor closing as outdated.
If you are experiencing this problem on a supported version of Drupal reopen the issue, by setting the status to 'Active', and provide complete steps to reproduce the issue (starting from "Install Drupal core").
Thanks!