See #3001919: Cannot delete SavedSearch entity due to pathauto.

The problem: In the Search API Saved Searches module we have a path field which just saves the path on which the search was originally executed. It has no relation to the Core Path, or to the Pathauto module. However, when deleting a saved search, pathauto_entity_delete() just assumes that the path field, if present, always belongs to this module – leading to a fatal error if it doesn’t.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

drunken monkey created an issue. See original summary.

drunken monkey’s picture

Easily fixed by some defensive coding.

Status: Needs review » Needs work

The last submitted patch, 2: 3006420-2--defensive_coding_in_pathauto_entity_delete.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

StryKaizer’s picture

Berdir’s picture

Status: Needs review » Needs work
+++ b/pathauto.module
@@ -104,7 +105,11 @@ function pathauto_entity_update(EntityInterface $entity) {
     \Drupal::service('pathauto.alias_storage_helper')->deleteEntityPathAll($entity);
-    $entity->get('path')->first()->get('pathauto')->purge();
+    $path = $entity->get('path')->first();
+    if ($path && $path instanceof ComplexDataInterface
+        && array_key_exists('pathauto', $path->getDataDefinition()->getFieldDefinition()->getPropertyDefinitions())) {
+      $path->get('pathauto')->purge();
+    }

That seems to be a really complicated way to fall back to field definition? Why not do something like $entity->getFieldDefinition('path')->getType() == 'path') after the hasField('path') in the above condition?

StryKaizer’s picture

Status: Needs work » Needs review
FileSize
680 bytes

Hah, you're right. That works too :). Thanks!

Patch attached

Berdir’s picture

Status: Needs review » Needs work

Thanks, but I think we should then also not call the delete alias method, so as I wrote, I'd put that condition on the existing if condition, or at least move the delete call inside as well.

shubham.prakash’s picture

Assigned: Unassigned » shubham.prakash
shubham.prakash’s picture

Assigned: shubham.prakash » Unassigned
Status: Needs work » Needs review
FileSize
757 bytes

This patch should fix the issue.

amateescu’s picture

Status: Needs review » Reviewed & tested by the community

Looks good.

Berdir’s picture

Status: Reviewed & tested by the community » Fixed

Committed.

Status: Fixed » Closed (fixed)

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