Problem/Motivation

When a menu contains links to routes with entity parameters where the entity cannot be loaded (e.g., deleted content, or system links like "My account" where the user entity isn't loadable in that context), the REST endpoint crashes with a fatal error:
Call to a member function uuid() on null
This happens in RestMenuItemsResource::getElementValue() in the case 'uuid': block when uuid is enabled as an output value (which it is by default).

Steps to reproduce

1. Have a menu with a system link that resolves to an entity route but where the entity can't be loaded (e.g., default "My account" link in the user menu)
2. Enable uuid in the REST menu items output values (enabled by default)
3. Request the menu via the REST endpoint
4. 500 error

Proposed resolution

Add a null check after load():

Remaining tasks

User interface changes

API changes

Data model changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

petar_basic created an issue. See original summary.

petar_basic’s picture

Status: Needs work » Needs review

Added a null check on the entity after load() — if the entity can't be loaded, uuid is simply left as null instead of crashing.

petar_basic’s picture

Assigned: petar_basic » Unassigned

batigolix made their first commit to this issue’s fork.

batigolix’s picture

Status: Needs review » Needs work

Hi Petar,

I tried to reproduce this but it was not so easy.

deleted content, or system links like "My account"

I tried both, but the error does not occur.

Do you have clear reproduction steps?

(I am happy to apply the proposed change, btw)

petar_basic’s picture

Assigned: Unassigned » petar_basic
fago’s picture

Status: Needs work » Reviewed & tested by the community

I'd assume this happens when you delete a content entity for which a menu-link was created manually. Since drupal does never take core of keeping references integer, all calling code must check for enttiy-references to be set. So the patch is the right fix imo.

batigolix’s picture

Assigned: petar_basic » Unassigned
Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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