Problem/Motivation
After installing and enabling the menu_items_visibility module on Drupal 11, the site throws a fatal error when trying to add a new menu link from the menu management page.
The error occurs because the module is calling the undefined function user_role_names() in menu_items_visibility.module.
Error message:
Error: Call to undefined function user_role_names() in menu_items_visibility_form_menu_link_content_menu_link_content_form_alter()
line 34 of modules/contrib/menu_items_visibility/menu_items_visibility.module
Steps to reproduce
- Install Drupal 11
- Install and enable the
menu_items_visibility module.
- Go to
/admin/structure/menu.
- Create a new menu or use an existing menu.
- Click on Add link for that menu.
The website shows an unexpected error page with the following fatal error:
Error: Call to undefined function user_role_names() in menu_items_visibility_form_menu_link_content_menu_link_content_form_alter()
line 34 of modules/contrib/menu_items_visibility/menu_items_visibility.module
Proposed resolution
Replace the deprecated user_role_names() function usage with a Drupal 11 compatible approach for loading user roles.
Comments
Comment #2
dkmishra commentedI noticed that the project currently only supports Drupal 10, while this fatal error occurs when testing on Drupal 11. The issue is caused by the use of the removed `user_role_names()` function in `menu_items_visibility.module`.
I tested the module on Drupal 10 and couldn't reproduce the issue—the module works as expected there. So this is not a bug affecting the currently supported version, but rather a Drupal 11 compatibility issue.
If Drupal 11 support is planned, replacing `user_role_names()` with the appropriate role storage service/API should resolve the problem.
For now, I understand if this is handled as a Drupal 11 compatibility issue rather than a general bug.
Comment #3
visabhishek commentedI am able to reproduces with drupal 11. and attached patch is working fine for me.
Comment #4
dkmishra commentedHi @visabhishek,
I tested the current
1.x-devbranch on Drupal 11.4 and can confirm that this issue is already resolved there.The menu link add/edit form works correctly, the role visibility options are displayed as expected, and I didn't encounter any regressions during my testing.
Thanks for the fix! This looks good to me, so RTBC from my side.