You are here

protected static function RequestFormatRouteFilter::getDefaultFormat in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Routing/RequestFormatRouteFilter.php \Drupal\Core\Routing\RequestFormatRouteFilter::getDefaultFormat()

Determines the default request format.

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. Also, if there are multiple routes which all require the same single format then use it.

Parameters

\Symfony\Component\Routing\RouteCollection $collection: The route collection to filter.

Return value

string The default format.

1 call to RequestFormatRouteFilter::getDefaultFormat()
RequestFormatRouteFilter::filter in core/lib/Drupal/Core/Routing/RequestFormatRouteFilter.php
Filters the route collection against a request and returns all matching routes.

File

core/lib/Drupal/Core/Routing/RequestFormatRouteFilter.php, line 93

Class

RequestFormatRouteFilter
Provides a route filter, which filters by the request format.

Namespace

Drupal\Core\Routing

Code

protected static function getDefaultFormat(RouteCollection $collection) {
  $formats = static::getAvailableFormats($collection);

  // The default format is 'html' unless ALL routes require the same format.
  return count($formats) === 1 ? reset($formats) : 'html';
}