TypeError Argument 1 must implement interface EntityInterface, null given - after deleting entity with filled menu_link field

Created on 4 June 2020, about 4 years ago
Updated 5 July 2023, 12 months ago

Menu Link field works well, when I create custom entity type, add menu_link field to it, and create entity with filled menu item - it show in menu and works.

When I delete menu_link field from entity type - all menu_link items in menu stays available and works as before.

But if after this - I delete entity, that was created before and have filled menu_link item (that becomes deleted from entity with field deletion, but stay in menu) - I got permanent fatal error on site:

TypeError: Argument 1 passed to Drupal\Core\Entity\EntityRepository::getTranslationFromContext() must implement interface Drupal\Core\Entity\EntityInterface, null given, called in web/modules/contrib/menu_link/src/Plugin/Menu/MenuLinkField.php on line 186 in Drupal\Core\Entity\EntityRepository->getTranslationFromContext() (line 99 of core/lib/Drupal/Core/Entity/EntityRepository.php).

This function called, when Drupal try to build menu tree for display menu block.

Seems this is because function Drupal\menu_link\Plugin\Menu\MenuLinkField::getEntity() he try to load entity, that not exist, and after this - getProperty() can't get property from empty object.

πŸ› Bug report
Status

Needs work

Version

2.0

Component

Code

Created by

πŸ‡¦πŸ‡²Armenia Murz Yerevan, Armenia

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Open on Drupal.org β†’
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 8
    last update about 1 year ago
    Waiting for branch to pass
  • πŸ‡ΊπŸ‡ΈUnited States pookmish

    The patch in #7 works for me. How is this issue 3 years old and still an active issue?

  • Status changed to Needs work about 1 year ago
  • πŸ‡―πŸ‡΅Japan ultrabob Japan

    According to the comment history, this still needs to have the existing menu link items deleted when the module is uninstalled, and that is not yet implemented.

  • πŸ‡ΊπŸ‡ΈUnited States pookmish

    Ultrabob, nobody said anything about in this issue related to uninstalling the module. This is specifically when deleting an item. Maybe it could be related but that's never been mentioned until your comment.

  • πŸ‡―πŸ‡΅Japan ultrabob Japan

    Apologies, I meant this

    1. Remove all related menu_link instances on delete field action, for prevent this behavior on new sites.

    I got my wires crossed while writing the comment, but I still don't see this in there.

  • πŸ‡§πŸ‡¬Bulgaria vuil Bulgaria πŸ‡§πŸ‡¬ πŸ‡ͺπŸ‡Ί 🌍
Production build 0.69.0 2024