Deleting a menu_link during a node_update hook causes a fatal error

Created on 4 July 2024, 6 months ago

Problem/Motivation

I have need to delete the menu link associated to a node during a hook_node_update, doing this programatically works fine, but because menu item extras hooks into the node edit form, doing it through the web UI causes a fatal error:

Error: Call to a member function set() on null in Drupal\menu_item_extras\Service\MenuLinkContentService->nodeSave() (line 307 of modules/contrib/menu_item_extras/src/Service/MenuLinkContentService.php).

This is because \Drupal\menu_item_extras\Service\MenuLinkContentService::nodeSave assumes that it'll either create a new entity or load an existing one. It doesn't cope with the fact that it could be told to load an entity, and then fail to do so.

Steps to reproduce

Delete the menu_link_content entity during a hook_node_update.

Proposed resolution

Return early from the method if a menu link fails to be loaded.

Remaining tasks

Raise the MR

User interface changes

None

API changes

None

Data model changes

None

🐛 Bug report
Status

Closed: won't fix

Version

2.0

Component

Code

Created by

🇬🇧United Kingdom steven jones

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

Comments & Activities

Production build 0.71.5 2024