Problem/Motivation

In includes/menu.inc, Radix adds a unique class based on the menu link title:

  // Add a unique class using the title.
  $title = strip_tags($element['#title']);
  $element['#attributes']['class'][] = 'menu-link-' . drupal_html_class($title);

There are cases where $element['#title'] is null. This is the result of a wonky condition that I can't reliably reproduce, but when it happens, there is a PHP 8.1 warning.

Steps to reproduce

See above.

Proposed resolution

Cast the argument to string. Or alternatively, check if the argument is null, and if it is, skip adding the class. Casting to string would mean that the end result was the same as on previous versions of PHP, which is probably the best for backward compatibility.

Remaining tasks

Patch and test.

User interface changes

None.

API changes

None.

Data model changes

None.

CommentFileSizeAuthor
#2 radix-php81-warning-3345887-2.patch505 bytescboyden

Comments

cboyden created an issue. See original summary.

cboyden’s picture

Assigned: cboyden » Unassigned
Status: Active » Needs review
StatusFileSize
new505 bytes

Patch is attached.

dsnopek’s picture

Status: Needs review » Reviewed & tested by the community

This seems fine to me! It's a very small change and keeps behavior the same as it would have been with previous versions of PHP, which reduces the chance of regressions.

doxigo’s picture

Thanks for the patch, pushed to the dev

  • doxigo committed d2be94c8 on 7.x-3.x authored by cboyden
    Issue #3345887 by cboyden, dsnopek, doxigo: PHP 8 warning in menu...
doxigo’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.