Router.php, "No route found for the specified format html. Supported formats: json, xml."

Created on 26 April 2024, 8 months ago

stack used:
- domain module (with domain_entity on) https://www.drupal.org/project/domain โ†’
- drupal/jsonapi_extras https://www.drupal.org/project/jsonapi_extras โ†’
- webforms
- Webforms Rest https://www.drupal.org/project/webform_rest โ†’

and when I call any REST endpoint, for example webform_rest//fields?_format=json
I get "No route found for the specified format html. Supported formats: json, XML."

The stack looks like below

array(
    0 => array(
        'file' => '.\\web\\core\\lib\\Drupal\\Core\\Routing\\Router.php',
        'line' => 280,
        'function' => 'filter',
        'class' => 'Drupal\\Core\\Routing\\RequestFormatRouteFilter',
        'type' => '->',
    ),
    1 => array(
        'file' => '.\\web\\core\\lib\\Drupal\\Core\\Routing\\Router.php',
        'line' => 126,
        'function' => 'applyRouteFilters',
        'class' => 'Drupal\\Core\\Routing\\Router',
        'type' => '->',
    ),
    2 => array(
        'file' => '.\\web\\core\\lib\\Drupal\\Core\\Routing\\Router.php',
        'line' => 103,
        'function' => 'matchRequest',
        'class' => 'Drupal\\Core\\Routing\\Router',
        'type' => '->',
    ),
    3 => array(
        'file' => '.\\web\\core\\lib\\Drupal\\Core\\Path\\PathValidator.php',
        'line' => 161,
        'function' => 'match',
        'class' => 'Drupal\\Core\\Routing\\Router',
        'type' => '->',
    ),
    4 => array(
        'file' => '.\\web\\core\\lib\\Drupal\\Core\\Path\\PathValidator.php',
        'line' => 122,
        'function' => 'getPathAttributes',
        'class' => 'Drupal\\Core\\Path\\PathValidator',
        'type' => '->',
    ),
    5 => array(
        'file' => '.\\web\\core\\lib\\Drupal\\Core\\Path\\PathValidator.php',
        'line' => 89,
        'function' => 'getUrl',
        'class' => 'Drupal\\Core\\Path\\PathValidator',
        'type' => '->',
    ),
    6 => array(
        'file' => '.\\web\\core\\lib\\Drupal\\Core\\Url.php',
        'line' => 427,
        'function' => 'getUrlIfValidWithoutAccessCheck',
        'class' => 'Drupal\\Core\\Path\\PathValidator',
        'type' => '->',
    ),
    7 => array(
        'file' => '.\\web\\core\\lib\\Drupal\\Core\\Url.php',
        'line' => 319,
        'function' => 'fromInternalUri',
        'class' => 'Drupal\\Core\\Url',
        'type' => '::',
    ),
    8 => array(
        'file' => '.\\web\\core\\lib\\Drupal\\Core\\Url.php',
        'line' => 221,
        'function' => 'fromUri',
        'class' => 'Drupal\\Core\\Url',
        'type' => '::',
    ),
    9 => array(
        'file' => '.\\web\\modules\\contrib\\domain_entity\\src\\HttpKernel\\DomainEntitySourcePathProcessor.php',
        'line' => 147,
        'function' => 'fromUserInput',
        'class' => 'Drupal\\Core\\Url',
        'type' => '::',
    ),
    10 => array(
        'file' => '.\\web\\core\\lib\\Drupal\\Core\\PathProcessor\\PathProcessorManager.php',
        'line' => 108,
        'function' => 'processOutbound',
        'class' => 'Drupal\\domain_entity\\HttpKernel\\DomainEntitySourcePathProcessor',
        'type' => '->',
    ),
    11 => array(
        'file' => '.\\web\\core\\lib\\Drupal\\Core\\Routing\\UrlGenerator.php',
        'line' => 388,
        'function' => 'processOutbound',
        'class' => 'Drupal\\Core\\PathProcessor\\PathProcessorManager',
        'type' => '->',
    ),
    12 => array(
        'file' => '.\\web\\core\\lib\\Drupal\\Core\\Routing\\UrlGenerator.php',
        'line' => 297,
        'function' => 'processPath',
        'class' => 'Drupal\\Core\\Routing\\UrlGenerator',
        'type' => '->',
    ),
    13 => array(
        'file' => '.\\web\\core\\lib\\Drupal\\Core\\Render\\MetadataBubblingUrlGenerator.php',
        'line' => 105,
        'function' => 'generateFromRoute',
        'class' => 'Drupal\\Core\\Routing\\UrlGenerator',

As you see DomainEntitySourcePathProcessor.php invokes Url::fromUserInput() and what he tries to do is basically detect if user has access to access this route in terms of Domain Entity logic. If for example I instantly return $path value form DomainEntitySourcePathProcessor::processOutbound() not doing any logic - then all works, no error. But I cant do that, the logic must happen.

And what happens later is that Symfony\Component\HttpFoundation\Request is recreated multiple times. But its constructor or factories does not care about _format value passed in any manner, it must be manually set, otherwise Request::duplicate() method must be used.

I have examined all the chain few times (this problem I observe for 10 months and its time to finally solve it, client needs that).
And my suggestion is to do change in web\core\lib\Drupal\Core\Routing\Router.php

  public function match($pathinfo): array {
    $request = Request::create($pathinfo);
    $request->getRequestFormat(\Drupal::request()->getRequestFormat()); // ADD THIS LINE

works good, solves the problem and nothing broken.

I will publish the patch soon.

๐Ÿ› Bug report
Status

Active

Version

8.8 โšฐ๏ธ

Component
Request processingย  โ†’

Last updated about 11 hours ago

No maintainer
Created by

๐Ÿ‡บ๐Ÿ‡ฆUkraine mykola dolynskyi Poltava

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024