This is a regression introduced by #2350797: Orphaned menu links when nodes are deleted if menu_link_ui is not enabled.

Problem

To reproduce:

1. Create a custom menu link that points at /admin/people
2. Create a user.
3. Delete (not disable) the user.
4. The custom menu link is deleted.

This appears to affect all cases where the custom menu link points at a route which is exposed as a link template of the deleted content entity, regardless of whether that link template is actually parameterised to that specific entity.

(Note that it doesn't happen with /node, even if you install the rest/hal/basic_auth modules. The link template "create" does point at "/node", but a menu link pointing at "/node" is resolved to view.frontpage.page_1 rather than entity.node.create due to the format restriction. Therefore $node->uriRelationships() will not pick it up and it will not be deleted. It is likely that if the Node entity were to expose `/admin/content` as a collection link template in the same manner as the User entity does, custom /admin/content menu links would also be deleted on node deletion.)

Proposed resolution

In menu_link_content_content_entity_predelete, check that the route parameters of the link actually include the entity. If they don't, it's a static link template (eg. collection) and should not be deleted.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cburschka created an issue. See original summary.

cburschka’s picture

Status: Active » Needs review
Issue tags: +Needs tests
FileSize
1002 bytes

Not sure about this one. It assumes that the parameter for the entity is named after the entity type, which is usually correct, but can be overridden in the route definition.

If we want to be completely correct/paranoid about this, we would need to load and inspect the actual route definition, check if any of its parameters are upcast to the entity in question, and then check if the value of that parameter actually matches the entity we're deleting.

Also needs test.

tstoeckler’s picture

Wow, this is a very interesting one. What your patch doesn't catch is revision routes (assuming they don't also contain the base entity ID). Maybe we should add a check for a $entity_type_id . '_revision' parameter, as well?

cburschka’s picture

From what I can tell, revision-specific routes can't actually be handled by the code currently because the revision parameter is not provided anywhere. Without that parameter, we likely can't find any menu links.

(In fact, revision-specific link templates currently cause a crash because Entity::uriRelationships() doesn't catch the MissingMandatoryParameterException, which is a separate bug: #2924338: Entity::uriRelationships() throws exceptions if an URL cannot be generated because of missing mandatory parameters.)

cburschka’s picture

Status: Needs review » Needs work

Wait, I missed a special case - the revision relationship itself automatically gets the revision parameter set by the entity. So I definitely should be handling that case in the patch, yes.

The problem I described just affects extra relationships like revision-delete or revision-revert (which hopefully shouldn't have any menu links pointing at them anyway).

cburschka’s picture

Status: Needs work » Needs review
FileSize
1.04 KB
705 bytes
cburschka’s picture

The test is actually just a few extra lines in the existing test function for the original issue.

The last submitted patch, 7: drupal-2926897-7-testonly.patch, failed testing. View results

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

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should 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.

cburschka’s picture

Status: Fixed » Closed (fixed)

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