PHP errors occurring when adding or editing a menu item

Created on 14 August 2024, about 1 month ago
Updated 29 August 2024, 18 days ago

Problem/Motivation

There are PHP errors occurring when attempting to add or edit a menu item. The problem happens because of a call to a (implicitly) static method in the Utils class from a function in sansdesordre.module. The static method references $this which is invalid because the class is not instantiated in this context.

Steps to reproduce

Create a menu.
Click 'Add link'.
Results:
"The website encountered an unexpected error. Please try again later."

Logged message:

Message	Error: Using $this when not in object context in Drupal\sansdesordre\Utils::getRouteName() (line 47 of /var/www/html/html/modules/contrib/sansdesordre/src/Utils.php)
#0 /var/www/html/html/modules/contrib/sansdesordre/sansdesordre.module(30): Drupal\sansdesordre\Utils::getRouteName()

There is a second error that occurs when the first issue is resolved:

Message	Error: Using $this when not in object context in Drupal\sansdesordre\Utils::getMenuLinkFromMlid() (line 62 of /var/www/html/html/modules/contrib/sansdesordre/src/Utils.php)
#0 /var/www/html/html/modules/contrib/sansdesordre/sansdesordre.module(49): Drupal\sansdesordre\Utils::getMenuLinkFromMlid('3812')

Proposed resolution

The Utils methods called from the .module file, are unnecessary wrappers around Drupal services. The calls to the Utils methods need to be replaced with direct calls to the Drupal services.

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada User Advocate

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

Comments & Activities

Production build 0.71.5 2024