Trying to edit embedded entities causes uncaught exception

Created on 23 January 2024, 10 months ago
Updated 15 July 2024, 4 months ago

Problem/Motivation

Core's Entity API does not guarantee that every content types always have the “edit” link defined in their annotation. In our case the File entity type which declares having only delete-form (with the path of /file/{file}/delete). In contrast, one of the most fully-fledged core content types, the Node has several others defined as well – besides the expected edit-form (URL path alias: /node/{node}/edit).

That being said, this contrib module entity_embed is apparently not prepared for those situations when an entity of such a type is being embedded. Assuming that simply concatenating words into a string is supposed to be a valid route in the system leads to this uncaught exception:

FastCGI sent in stderr: "PHP message: Uncaught PHP Exception Symfony\Component\Routing\Exception\RouteNotFoundException: "Route "entity.file.edit_form" does not exist." at /var/www/example.com/core/lib/Drupal/Core/Routing/RouteProvider.php line 206" while reading response header from upstream, client: 100.6.43.78, server: example.com, request: "GET /entity-embed/edit-embedded/file/ffa0e0e8-e740-461a-be3e-1e1c98fb7a75 HTTP/2.0", upstream: "fastcgi://unix:/var/run/php/php8.1-fpm.sock:", host: "example.com", referrer: "https://example.com/node/246/edit"

Steps to reproduce

  1. Create a new embed button for managed File entity type
  2. Add this embed button to the WYSIWYG toolbar of a text format
  3. Ensure that at least one managed file exists on the site
  4. Bring up the WYIWYG editor in any context (eg. the body field of a node when creating/editing)
  5. Click the embed button, insert a managed file into the formatted text field
  6. Submit the form
  7. Reopen the recently created/edited content for editing again
  8. Hover over the embedded managed file
  9. If the cogwheel icon is not grayed out then click it
  10. Exception happens.

However, might worth to mention that there is some protection already working in certain conditions. For example, on the screencast below the cogwheel icon is rendered already inactive with a notification (“You do not have the permissions needed to edit this file”) appearing on hover:

Proposed resolution

My suggestion is to implement some logic for A) checking whether the route exists; and B) if not, then provide an existing route instead.

Searching Drupal core's issue queue for the “entity system” component brings up 80+ open tickets about routing. Personally, I do not believe that the situation of entity-type form links will change soon. This is why I suggest preparing the module's intelligence instead of waiting for any core issue to be resolved.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Needs review

Version

1.5

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @Nelo_Drup
  • 🇺🇸United States Chad Ketchum

    I'm having the same issue. My log Message Symfony\Component\Routing\Exception\RouteNotFoundException: Route "entity.file.edit_form" does not exist. in Drupal\Core\Routing\RouteProvider->getRouteByName() (line 208 of /var/www/html/docroot/core/lib/Drupal/Core/Routing/RouteProvider.php).
    Severity Error

    Operations
    Backtrace
    #0 /var/www/html/docroot/core/lib/Drupal/Core/Routing/UrlGenerator.php(443): Drupal\Core\Routing\RouteProvider->getRouteByName()
    #1 /var/www/html/docroot/core/lib/Drupal/Core/Routing/UrlGenerator.php(276): Drupal\Core\Routing\UrlGenerator->getRoute()
    #2 /var/www/html/docroot/core/lib/Drupal/Core/Render/MetadataBubblingUrlGenerator.php(108): Drupal\Core\Routing\UrlGenerator->generateFromRoute()
    #3 /var/www/html/docroot/core/lib/Drupal/Core/Url.php(765): Drupal\Core\Render\MetadataBubblingUrlGenerator->generateFromRoute()
    #4 /var/www/html/docroot/core/lib/Drupal/Core/Controller/ControllerBase.php(270): Drupal\Core\Url->toString()
    #5 /var/www/html/docroot/modules/contrib/entity_embed/src/Controller/EditEmbeddedEntity.php(22): Drupal\Core\Controller\ControllerBase->redirect()
    #6 [internal function]: Drupal\entity_embed\Controller\EditEmbeddedEntity->edit()
    #7 /var/www/html/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
    #8 /var/www/html/docroot/core/lib/Drupal/Core/Render/Renderer.php(638): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #9 /var/www/html/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(121): Drupal\Core\Render\Renderer->executeInRenderContext()
    #10 /var/www/html/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() in my case it happens spacificly when you click the cog Edit the Embedded Entity (Opens in new tab)
    #11 /var/www/html/docroot/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #12 /var/www/html/docroot/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
    #13 /var/www/html/docroot/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Symfony\Component\HttpKernel\HttpKernel->handle()
    #14 /var/www/html/docroot/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
    #15 /var/www/html/docroot/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
    #16 /var/www/html/docroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\ContentLength->handle()
    #17 /var/www/html/docroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass()
    #18 /var/www/html/docroot/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle()
    #19 /var/www/html/docroot/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
    #20 /var/www/html/docroot/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
    #21 /var/www/html/docroot/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle()
    #22 /var/www/html/docroot/core/lib/Drupal/Core/DrupalKernel.php(741): Drupal\Core\StackMiddleware\StackedHttpKernel->handle()
    #23 /var/www/html/docroot/index.php(19): Drupal\Core\DrupalKernel->handle()
    #24 {main}

  • 🇭🇺Hungary Balu Ertl Budapest 🇪🇺

    Balu Ertl made their first commit to this issue’s fork.

  • 🇭🇺Hungary Balu Ertl Budapest 🇪🇺

    Balu Ertl changed the visibility of the branch 3416512-error-after-updating to hidden.

  • 🇭🇺Hungary Balu Ertl Budapest 🇪🇺

    As it turned out, it has nothing to do neither with the core version upgrade nor with entity_browser module so we can rule them out from debugging. After testing on both 10.1.x and 10.2.x core versions I found the root cause of the issue, so updating the ticket summary accordingly.

  • 🇭🇺Hungary Balu Ertl Budapest 🇪🇺
  • Status changed to Needs review 4 months ago
  • 🇭🇺Hungary Balu Ertl Budapest 🇪🇺

    In my MR, I suggest following a somewhat different approach: instead of juggling with raw route names while handling the risk of their inexistence, why not ask the entity instance itself about their operation links?

    Also, in the very unlikely situation, if still have not found any viable route to redirect, we can resort to displaying a plain text message notifying the user about nothing wrong they did, but the embedded entity has some limitations.

  • Pipeline finished with Failed
    4 months ago
    Total: 903s
    #224713
Production build 0.71.5 2024