Prevent passing NULL into explode() - MenuLinkContentForm

Created on 7 March 2024, 10 months ago

Problem/Motivation

In some cases, if there's an orphaned menu link, there will be PHP warnings generated in MenuLinkContentForm.

Deprecated function: explode(): Passing null to parameter #2 ($string) of type string is deprecated in Drupal\menu_link_content\Form\MenuLinkContentForm->buildEntity() 
Warning: Undefined array key 1 in Drupal\menu_link_content\Form\MenuLinkContentForm->buildEntity()

Steps to reproduce

1. Install group_content_menu
2. Create a link in the main menu, take note of the ID
3. Run the following using your ID: drush php:eval '$link=\Drupal\menu_link_content\Entity\MenuLinkContent::load(YOUR_ID);$link->set("menu_name","group_menu_link_content-999");$link->save();'
4. Go to /admin/structure/menu/item/YOUR_ID/edit, and re-save the link.
5. View your logs, notice the php warnings

Proposed resolution

Check if the menu_parent value if set before passing the value into explode

Remaining tasks

Open a PR

User interface changes

API changes

Data model changes

Release notes snippet

๐Ÿ› Bug report
Status

Needs work

Version

11.0 ๐Ÿ”ฅ

Component
Menu link contentย  โ†’

Last updated 3 days ago

Created by

๐Ÿ‡ธ๐Ÿ‡ฎSlovenia alecsmrekar

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024