Passing NULL to Unicode::truncate() in MenuParentSelectorForm causes deprecations on PHP 8.1

Created on 14 March 2023, over 1 year ago
Updated 10 April 2023, about 1 year ago

Problem/Motivation

\Drupal\Component\Utility\Unicode::truncate() allows passing NULL as string to truncate - the cause of deprecation on PHP 8.1.

Menu links can have no title, in my case this is a <nolink> container without title...

Steps to reproduce

Create a menu item without title and with <nolink> path, and add links below.

Then go to a bundle configuration page (Ex: /admin/structure/types/manage/mybundle )

Proposed resolution

In MenuParentSelectorForm, check that link title is not NULL before calling Unicode::truncate()

Remaining tasks

Maybe some tests ? But unfortunatly I don't know how to write tests...

🐛 Bug report
Status

Needs work

Version

10.1

Component
Menu system 

Last updated 4 days ago

Created by

🇫🇷France opi

Live updates comments and jobs are added and updated live.
  • PHP 8.1

    The issue particularly affects sites running on PHP version 8.1.0 or later.

Sign in to follow issues

Comments & Activities

  • Issue created by @opi
  • Status changed to Needs review about 1 year ago
  • 🇮🇳India Ranjit1032002

    Created a patch for the issue mentioned, please review.
    Thank You.

  • Status changed to Needs work about 1 year ago
  • 🇺🇸United States smustgrave

    How are you adding a menu item without a title when it's a required field?

    Also these kind of issues just slapping an is_null check isn't usually the best approach. This could be a different issue and it's just being covered up.

  • Status changed to Needs review about 1 year ago
  • 🇮🇳India rckstr_rohan

    Added a patch with interdiff to #3, adding Untitled as title when title is not present.

  • Status changed to Needs work about 1 year ago
  • 🇺🇸United States smustgrave

    @rckstr_rohan thank you for the interest but you've been working on a number of these tickets now. Adding just a check isn't usually a good solution. As it could be hiding a deeper issue.

    If steps are not provided to reproduce that will be needed. #4 you'll see I asked for clarity on the steps.

    As a bug it will need a test case.

    Please do some checks before putting into review.

    Thanks

Production build 0.69.0 2024