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

  1. Install Drupal 11
  2. Install and enable the menu_items_visibility module.
  3. Go to /admin/structure/menu.
  4. Create a new menu or use an existing menu.
  5. 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.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

gurkawal created an issue. See original summary.

dkmishra’s picture

I 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.

visabhishek’s picture

Status: Active » Needs review
StatusFileSize
new1.46 KB

I am able to reproduces with drupal 11. and attached patch is working fine for me.

dkmishra’s picture

Hi @visabhishek,

I tested the current 1.x-dev branch 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.