.../Core/Routing/RequestFormatRouteFilter.php | 27 ++++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/core/lib/Drupal/Core/Routing/RequestFormatRouteFilter.php b/core/lib/Drupal/Core/Routing/RequestFormatRouteFilter.php index 8f34426..9654d4c 100644 --- a/core/lib/Drupal/Core/Routing/RequestFormatRouteFilter.php +++ b/core/lib/Drupal/Core/Routing/RequestFormatRouteFilter.php @@ -66,7 +66,9 @@ public function filter(RouteCollection $collection, Request $request) { * * By default, use 'html' as the default format. But when there's only a * single route match, and that route specifies a '_format' requirement - * listing a single format, then use that as the default format. + * listing a single format, then use that as the default format. Also, if + * there are multiple routes which all require the same single format then + * use it. * * @param \Symfony\Component\Routing\RouteCollection $collection * The route collection to filter. @@ -76,14 +78,25 @@ public function filter(RouteCollection $collection, Request $request) { */ protected static function getDefaultFormat(RouteCollection $collection) { $default_format = 'html'; - if ($collection->count() === 1) { - $only_route = $collection->getIterator()->current(); - $required_format = $only_route->getRequirement('_format'); - if (strpos($required_format, '|') === FALSE) { - $default_format = $required_format; + $iterator = $collection->getIterator(); + $first_route = $iterator->current(); + $required_format = $first_route->getRequirement('_format'); + if (strpos($required_format, '|') !== FALSE) { + return $default_format; + } + if (!$iterator->valid()) { + return $required_format; + } + else { + $iterator->next(); + for ($iterator; $iterator->valid(); $iterator->next()) { + $route = $iterator->current(); + if ($required_format != $route->getRequirement('_format')) { + return $default_format; + } } + return $required_format; } - return $default_format; } }