You are here

protected function NegotiationMiddleware::getContentType in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php \Drupal\Core\StackMiddleware\NegotiationMiddleware::getContentType()
  2. 9 core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php \Drupal\Core\StackMiddleware\NegotiationMiddleware::getContentType()

Gets the normalized type of a request.

The normalized type is a short, lowercase version of the format, such as 'html', 'json' or 'atom'.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request object from which to extract the content type.

Return value

string The normalized type of a given request.

1 method overrides NegotiationMiddleware::getContentType()
StubNegotiationMiddleware::getContentType in core/tests/Drupal/Tests/Core/StackMiddleware/NegotiationMiddlewareTest.php
Gets the normalized type of a request.

File

core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php, line 81

Class

NegotiationMiddleware
Provides a middleware to determine the content type upon the accept header.

Namespace

Drupal\Core\StackMiddleware

Code

protected function getContentType(Request $request) {

  // AJAX iframe uploads need special handling, because they contain a JSON
  // response wrapped in <textarea>.
  if ($request->request
    ->get('ajax_iframe_upload', FALSE)) {
    return 'iframeupload';
  }
  if ($request->query
    ->has('_format')) {
    return $request->query
      ->get('_format');
  }

  // No format was specified in the request.
  return NULL;
}