Just started working with this module in-tandem with Layout Builder and running into an issue where upon enabling Layout Builder for the menu under the Manage Display tab.

I can no longer visit the Manage Display tab and get this error:
Drupal\Core\Database\InvalidQueryException: Query condition 'menu_link_content.uuid IN ()' cannot be empty. in Drupal\Core\Database\Query\Condition->condition() (line 103 of /var/www/docroot/core/lib/Drupal/Core/Database/Query/Condition.php).

Which appears to be coming from src/Entity/MenuItemExtrasMenuLinkContent.php on line 32. The parent_uuid value seems to be null (and $this->getParentId() seems to return an incomprehensible value that looks like a generated value from Devel) and so the EntityTypeManager throws an error because uuid cannot be null when searching.

There might be an underlying issue that I cannot seem to find, but adding a simple null check here seems to alleviate the issue.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Justin Langley’s picture

ozin’s picture

Status: Active » Needs review
PCate’s picture

I ran into the same error and the patch fixed it.

ozin’s picture

Hi @justin@codekoalas.com

Thanks for the patch! What do you think about a test coverage for this case?

JulianVJ’s picture

Hi
I also ran into the same error and I've been debugging a little because I didn't find this issue.
I want to write down here what I have found in case it could be of help to someone else

This error happens with a sample entity generated by Layout Builder and stored in TempStore. It seems that Layout Builder generates this samples entities when a new supported entity is created, this is what happens when Menu Item Extras is enabled. See: core\modules\layout_builder\src\Entity\LayoutBuilderSampleEntityGenerator.php -> get().

The patch attached by @justincodekoalascom works correctly. I think is a good idea to add a test coverage

m.abdulqader’s picture

The patch fixes the issue for us.

Thank you

  • ozin committed 11210c2 on 8.x-2.x authored by justin@codekoalas.com
    Issue #3032279 by justin@codekoalas.com: Menu Link Parent ID is null
    
  • ozin authored 678d66c on 8.x-2.x
    Merge pull request #151 from ozin7/issue/3032279-parent-null
    
    Issue #...
jmarcou’s picture

Status: Needs review » Needs work

Seems like this is not entirely fixed, I'm now getting a :

Notice: Undefined offset: 1 in Drupal\menu_item_extras\Entity\MenuItemExtrasMenuLinkContent->getCacheTagsToInvalidate() (line 32 of modules/contrib/menu_item_extras/src/Entity/MenuItemExtrasMenuLinkContent.php).

(you need to clear the cache every time you reload your page to see this, because of the cache).

This is caused by the fact that I have created a static menu link inside a module (my_module.links.menu.yml) that extends MenuLinkDefault, these kind of links does not work as other menu links and don't have an ID like "menu_link_content:{uuid}", in my case the ID looks like "my_module.my_menu_name".

These kind of links should not be loaded like other menu links, I don't know how to do it, but I think it should definitely call the cache methods of my class that extends MenuLinkDefault.

jmarcou’s picture

In addition to you previous commit, I updated the code to create a new patch (for the people that are on the
8.x-2.4 version, you'll need to apply patch 3032279-1.patch and 3032279-2.patch in order to make it works).

So finally, my solution was to check for the prefix string "menu_link_content:" instead of exploding the string by ":".
Then if it has the prefix, I used the same solution as before (loading the menu link content entity from storage), otherwise I use the MenuLinkManager service, which allows to load static menu links as MenuLinkInterface, on which I can call the getCacheTags() method.

jmarcou’s picture

Status: Needs work » Needs review
voleger’s picture

Status: Needs review » Reviewed & tested by the community

Looks good. Thanks a lot @jmarcou for your so descriptive comments.

rodrigoaguilera’s picture

I can confirm the patch in #10 works as intended. please commit it

  • ozin authored 067b36b on 8.x-2.x
    Issue #3032279 by Justin Langley, jmarcou, ozin: Menu Link Parent ID is...
  • ozin committed e15cde2 on 8.x-2.x authored by jmarcou
    Issue #3032279 by Justin Langley, jmarcou, ozin: Menu Link Parent ID is...
Justin Langley’s picture

I had totally forgotten I submitted this a while back! Glad to see someone improved on what I was trying to do. I ended up back here because I was searching for the exact issue mentioned in #9.

voleger’s picture

Status: Reviewed & tested by the community » Fixed

Fix already published in 8.x-2.5 release version. Thanks.

Status: Fixed » Closed (fixed)

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