Problem/Motivation

When an entity with an external canonical url is deleted an exception is thrown via redirect_entity_delete:

UnexpectedValueException: Unrouted URIs do not have internal representations. in Drupal\Core\Url->getInternalPath()

This is due to the call to $entity->toUrl('canonical')->getInternalPath() without checking whether the url is routed or not.

I believe this was introduced by #2888903: Delete redirects even the entity lacks the path field

Steps to reproduce:
* Install https://www.drupal.org/project/linky and redirect
* Add a managed link entity
* Try to delete the entity

Proposed resolution

Check the canonical url is routed before attempted to delete anything.

Remaining tasks

Code
Tests

Comments

acbramley created an issue. See original summary.

acbramley’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new690 bytes

Here's the fix, still probably need tests for this delete hook and the fix as well though.

acbramley’s picture

Issue summary: View changes
nikunjkotecha’s picture

StatusFileSize
new1.24 KB

For me same thing is happening but when disabling the module lightning_media.

Symfony\Component\Routing\Exception\RouteNotFoundException: Route "entity.entity_browser.canonical" does not exist. in                                                                       [error]
/var/www/docroot/core/lib/Drupal/Core/Routing/RouteProvider.php:190
Stack trace:
#0 /var/www/docroot/core/lib/Drupal/Core/Routing/UrlGenerator.php(421): Drupal\Core\Routing\RouteProvider->getRouteByName('entity.entity_b...')
#1 /var/www/docroot/core/lib/Drupal/Core/Routing/UrlGenerator.php(130): Drupal\Core\Routing\UrlGenerator->getRoute('entity.entity_b...')
#2 /var/www/docroot/core/lib/Drupal/Core/Render/MetadataBubblingUrlGenerator.php(68): Drupal\Core\Routing\UrlGenerator->getPathFromRoute('entity.entity_b...', Array)
#3 /var/www/docroot/core/lib/Drupal/Core/Url.php(790): Drupal\Core\Render\MetadataBubblingUrlGenerator->getPathFromRoute('entity.entity_b...', Array)
#4 /var/www/docroot/modules/contrib/redirect/redirect.module(83): Drupal\Core\Url->getInternalPath()
#5 [internal function]: redirect_entity_delete(Object(Drupal\entity_browser\Entity\EntityBrowser), 'entity_browser')
#6 /var/www/docroot/core/lib/Drupal/Core/Extension/ModuleHandler.php(402): call_user_func_array('redirect_entity...', Array)
#7 /var/www/docroot/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php(378): Drupal\Core\Extension\ModuleHandler->invokeAll('entity_delete', Array)
#8 /var/www/docroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php(369): Drupal\Core\Config\Entity\ConfigEntityStorage->invokeHook('delete',
Object(Drupal\entity_browser\Entity\EntityBrowser))
#9 /var/www/docroot/core/lib/Drupal/Core/Entity/Entity.php(385): Drupal\Core\Entity\EntityStorageBase->delete(Array)
#10 /var/www/docroot/core/lib/Drupal/Core/Config/ConfigManager.php(203): Drupal\Core\Entity\Entity->delete()
#11 /var/www/docroot/core/lib/Drupal/Core/Extension/ModuleInstaller.php(402): Drupal\Core\Config\ConfigManager->uninstall('module', 'lightning_media')
pingwin4eg’s picture

  • Berdir committed 8f26f24 on 8.x-1.x authored by nikunjkotecha
    Issue #2935026 by acbramley, nikunjkotecha: Deleting entity with...
berdir’s picture

Status: Needs review » Fixed

Thanks, committed. Fixed the comment, has nothing to do with uninstalling modules.

berdir’s picture

Status: Fixed » Closed (fixed)

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

idebr’s picture

#7 While this issue is not strictly related to uninstalling modules, the error (also) occurs when an entity type has a canonical link template but does not have a canonical route. This often happens with configuration entity types in the contrib space, such as Entity Browser. I am currently running into this issue with LDAP, see #2961668: LDAP configuration entity types define a canonical link template but do not have a canonical route

leisurman’s picture

I am getting this error when trying to edit any entity browsers. I can access the widget tab here. /admin/config/content/entity_browser/image_browser/widgets
The edit tab throws the error.
/admin/config/content/entity_browser/media_browser_ckeditor/edit

Symfony\Component\Routing\Exception\RouteNotFoundException: Route "entity.entity_browser.canonical" does not exist. in Drupal\Core\Routing\RouteProvider->getRouteByName() (line 201 of 
/var/www/html/fda1/docroot/core/lib/Drupal/Core/Routing/RouteProvider.php).

I have tried all of the patches from these issues:
https://www.drupal.org/project/redirect/issues/2932263
https://www.drupal.org/project/redirect/issues/2935026
https://www.drupal.org/project/redirect/issues/2888903

I tried upgrading Redirect Version: 8.x-1.4 to the dev version 8.x-1.x-dev. It did not fix the issue.

We are using Drupal Version 8.6.17, Lightning 8.x-3.207
Redirect Version: 8.x-1.4
Entity Browser version: 8.x-2.1

berdir’s picture

This issue was only about deleting, it was never a problem with editing. Most likely some other module is calling to Url(), you need to enable verbose error logging and check the backtrace.