Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
In core/modules/menu_link_content/src/Plugin/Menu/MenuLinkContent.php line 201
The documentation says that it should return the menu link ID but it was not returning anything.
/**
* Returns the unique ID representing the menu link.
*
* @return string
* The menu link ID.
*/
protected function getUuid() {
$this->getDerivativeId();
}
Comment | File | Size | Author |
---|---|---|---|
#21 | 2737741-21.patch | 1.78 KB | amateescu |
#21 | 2737741-21-test-only.patch | 1.26 KB | amateescu |
#2 | drupal-menulinkcontent-getuuid-return-missing-2737741-2.patch | 533 bytes | anoopjohn |
Comments
Comment #2
anoopjohn CreditAttribution: anoopjohn at Zyxware Technologies commentedPlease find attached a patch for the same. Should there be an update in tests as well?
Comment #3
anoopjohn CreditAttribution: anoopjohn at Zyxware Technologies commentedComment #4
markdorisonThis looks good to my eyes.
Comment #5
Mile23+1 on @markdorison's assessment. Patch applies, looks right.
Clearly we don't have a test for it, however, and I wonder if it's dead code.
MenuLinkContent::getEntity()
calls it as a fallback. I'm pretty sure all other calls togetUuid()
are on other entity types.Since we're figuring out the disparity between the docs and the code here, we should make this change, but eventually we'll need to figure out why we have this method.
Comment #6
Mile23Blocking #2722647: [Meta] Fix Drupal.Commenting.FunctionComment.InvalidNoReturn
Comment #7
alexpottGiven the code is not relied upon anywhere, I think we should add a test. Especially given that the fallback would appear to not work.
Comment #9
_Archy_ CreditAttribution: _Archy_ at PitechPlus commentedComment #10
_Archy_ CreditAttribution: _Archy_ at PitechPlus commentedThis issue happens when the website is enabled and can break the website. The getUuid() is only called in the getEntity() in the same class and this method only called internally aswell, just in the case in which the website is multilingual. I've encountered it, but cannot reproduce it.
Will try to create a test to break it. This will be my first test, but this issue needs to be fixed .. it's been 5 months..
Comment #11
BarisW CreditAttribution: BarisW at LimoenGroen commentedArchy, any success with writing the tests? If not, please un-assign the issue from your name so others can look into it.
Comment #12
_Archy_ CreditAttribution: _Archy_ at PitechPlus commentedSorry forgot about this. I've tried to create a test, but had a really hard time figuring out where to put it and testing my test. I'll leave it to someone who knows better.
Comment #16
shaaldrupal 8.4.4 website.
I created a menu item under Administration menu.
Then I try deleting the menu item I just created and got an error.
I applied the patch, and it fixed the issue
(menu item got deleted, and the website is working!)
Comment #17
hablat CreditAttribution: hablat commentedI manged to reproduce this error with admin_tollbars 8.x-1.22.
1.) Visit /admin/structure/menu
2.) Edit a menu and add a sub menu link of 3 levels down
3.) Delete the newly created menu link
4.) Error is shown
It seems admin_tollbar is using menu cache which still has the deleted menu link and requests for its ID leading to the error.
clearing menu cache (menu_cache_clear_all()) on admin_toolbar module before the process that triggers the error seems to fix it.
What i don't understand is why does core have the getUuid fallback when entity storage doesn't return the entity ID. Shouldnt that be enough to say that the entity doesn't exist?
edit: Also using the patch does fix the initial error right after deleting the menu. But when you try to log back in as an administrator the same error comes up.
Comment #18
jeqqI was also trying to implement a test for this, but I had a hard time to implement one that would reproduce the error. In my case I can reproduce the issue with the Multiversion + Workspace + Replication modules. When the content is replicated there can be some cases when deleting the node, it tries to deleted the menu link too and it has to look for the menu link content by ID. Because the menu link content ID can be missing in the plugin definition, it tries to load it by UUID, at that moment it fails because it can't find the menu link content (even it exists).
Comment #20
borisson_@jeqq: it would be really interesting to see if we can reproduce this issue with just core.
This fix is correct, but I don't know how a test for this can be written.
Comment #21
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedI also tried to reproduce this in a test and couldn't do it, so how about we settle for a unit test?
Comment #23
jeqqLooks good!
Comment #24
alexpottYep a unit test is good to have here.
Committed and pushed 39f95a14fb to 8.7.x and 3c90042bd6 to 8.6.x. Thanks!
Comment #28
stopopol CreditAttribution: stopopol commentedI just re-encountered this error message Drupal\Component\Plugin\Exception\PluginException: Entity not found through the menu link plugin definition and could not fallback on UUID '535a38ee-d54d-45ff-9c09-b27541950dc9' in Drupal\menu_link_content\Plugin\Menu\MenuLinkContent->getEntity() (line 157 of /var/www/html/drupal/web/core/modules/menu_link_content/src/Plugin/Menu/MenuLinkContent.php).
on Drupal 8.7.5.
Nothing fixed it except going into the database and deleting the respective menu item (which had a NULL value on the route name.
This bug came to be when I batch-deleted menu links using the uninstall functionality.