Problem/Motivation

When using the Druxt module with Drupal 11, accessing the /router/translate-path?path=%2F endpoint fails with a TypeError. The error occurs in the ViewsPathTranslatorSubscriber class when processing view routes, specifically when calling Url::fromRoute().

The error message is:

TypeError: Drupal\Core\Render\MetadataBubblingUrlGenerator::generateFromRoute(): Argument #1 ($name) must be of type string, Symfony\Component\Routing\Route given, called in /var/www/html/web/core/lib/Drupal/Core/Url.php on line 773 in Drupal\Core\Render\MetadataBubblingUrlGenerator->generateFromRoute() (line 104 of /var/www/html/web/core/lib/Drupal/Core/Render/MetadataBubblingUrlGenerator.php).

This breaks the decoupled router functionality for views in Drupal 11, preventing proper path translation for decoupled frontends using Druxt.

Steps to reproduce

  1. Install Drupal 11 with the Druxt module (version 1.2.x)
  2. Enable the decoupled_router and jsonapi_views modules
  3. Access a URL like http://example.com/router/translate-path?path=%2F (or any path that resolves to a view)
  4. Observe the TypeError in the response

Proposed resolution

Update the ViewsPathTranslatorSubscriber::onPathTranslation() method to pass the route name string instead of the Route object to Url::fromRoute().

Current code (line 65-66):

$route = $match_info[RouteObjectInterface::ROUTE_OBJECT];
$resolved_url = Url::fromRoute($route, [], ['absolute' => TRUE])->toString(TRUE);

Fixed code:

$route_name = $match_info[RouteObjectInterface::ROUTE_NAME];
$resolved_url = Url::fromRoute($route_name, [], ['absolute' => TRUE])->toString(TRUE);

This change aligns with how the parent RouterPathTranslatorSubscriber class handles route URL generation and is compatible with Drupal 11's stricter type checking in the URL generation system.

Remaining tasks

  • Apply the patch to fix the ViewsPathTranslatorSubscriber
  • Test the fix with Drupal 11
  • Ensure backward compatibility with Drupal 9 and 10

User interface changes

None. This is an internal API fix that doesn't affect the user interface.

API changes

None. The fix maintains the same public API and behavior - it only corrects the internal implementation to be compatible with Drupal 11.

Data model changes

None. This fix only affects how URLs are generated from route information, not the underlying data structures.

Comments

deciphered created an issue. See original summary.

deciphered’s picture

Issue summary: View changes
deciphered’s picture

Status: Active » Needs review
StatusFileSize
new875 bytes