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();
  }
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

anoopjohn created an issue. See original summary.

anoopjohn’s picture

Please find attached a patch for the same. Should there be an update in tests as well?

anoopjohn’s picture

Status: Active » Needs review
markdorison’s picture

This looks good to my eyes.

Mile23’s picture

Status: Needs review » Reviewed & tested by the community

+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 to getUuid() 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.

Mile23’s picture

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Given the code is not relied upon anywhere, I think we should add a test. Especially given that the fallback would appear to not work.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

_Archy_’s picture

_Archy_’s picture

Assigned: Unassigned » _Archy_

This 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..

BarisW’s picture

Archy, any success with writing the tests? If not, please un-assign the issue from your name so others can look into it.

_Archy_’s picture

Assigned: _Archy_ » Unassigned

Sorry 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.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

shaal’s picture

drupal 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!)

hablat’s picture

I 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.

jeqq’s picture

I 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).

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

borisson_’s picture

@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.

amateescu’s picture

Title: getUuid() in class MenuLinkContent not returning any value » Drupal\menu_link_content\Plugin\Menu\MenuLinkContent::getUuid() does not return any value
Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
1.26 KB
1.78 KB

I also tried to reproduce this in a test and couldn't do it, so how about we settle for a unit test?

The last submitted patch, 21: 2737741-21-test-only.patch, failed testing. View results

jeqq’s picture

Status: Needs review » Reviewed & tested by the community

Looks good!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Yep a unit test is good to have here.

Committed and pushed 39f95a14fb to 8.7.x and 3c90042bd6 to 8.6.x. Thanks!

  • alexpott committed 39f95a1 on 8.7.x
    Issue #2737741 by amateescu, anoopjohn: Drupal\menu_link_content\Plugin\...

  • alexpott committed 3c90042 on 8.6.x
    Issue #2737741 by amateescu, anoopjohn: Drupal\menu_link_content\Plugin\...

Status: Fixed » Closed (fixed)

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

stopopol’s picture

I 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.