RouteNotFoundException when a jsonapi individual route is not available

Created on 13 October 2020, over 3 years ago
Updated 21 May 2023, about 1 year ago

Problem/Motivation

When jsonapi is enabled, and jsonapi routes were removed for security reasons, RouterPathTranslatorSubscriber fails to execute because it expects that ".individual" routes are always available:

Route "jsonapi.node--event.individual" does not exist.
#0 /var/www/html/web/core/lib/Drupal/Core/Routing/UrlGenerator.php(426):
Drupal\Core\Routing\RouteProvider->getRouteByName('jsonapi.node--e...')
#1 /var/www/html/web/core/lib/Drupal/Core/Routing/UrlGenerator.php(271):
Drupal\Core\Routing\UrlGenerator->getRoute('jsonapi.node--e...')
#2 /var/www/html/web/core/lib/Drupal/Core/Render/MetadataBubblingUrlGenerator.php(105):
Drupal\Core\Routing\UrlGenerator->generateFromRoute('jsonapi.node--e...', Array, Array, true)
#3 /var/www/html/web/core/lib/Drupal/Core/Url.php(754):
Drupal\Core\Render\MetadataBubblingUrlGenerator->generateFromRoute('jsonapi.node--e...', Array, Array, true)
#4 /var/www/html/web/modules/contrib/decoupled_router/src/EventSubscriber/RouterPathTranslatorSubscriber.php(215):
Drupal\Core\Url->toString(true)

etc.

Steps to reproduce

  1. Disable Redirect (if relevant).
  2. Enable Decoupled Router.
  3. Enable JSON API (from core).
  4. With a RouteSubscriber, remove some jsonapi routes as shown here: https://www.drupal.org/docs/core-modules-and-themes/core-modules/jsonapi... .
  5. Have a service (or anything suitable for the task) call the translators by calling PathTranslator::translate().
  6. RouterPathTranslatorSubscriber fails in getEntityRouteParameterName()

Proposed resolution

Add checks around getRouteByName() in getEntityRouteParameterName().

OR

Refactor the code around getEntityRouteParameterName() (there are todos listed here).

🐛 Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

🇫🇷France Dakwamine

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024