You are here

protected function NegotiationMiddleware::getContentType in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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.

2 calls to NegotiationMiddleware::getContentType()
NegotiationMiddleware::handle in core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php
Handles a Request to convert it to a Response.
StubNegotiationMiddleware::getContentType in core/tests/Drupal/Tests/Core/StackMiddleware/NegotiationMiddlewareTest.php
Gets the normalized type of a 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 85
Contains \Drupal\Core\StackMiddleware\NegotiationMiddleware.

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
    ->get('ajax_iframe_upload', FALSE)) {
    return 'iframeupload';
  }
  if ($request->query
    ->has('_format')) {
    return $request->query
      ->get('_format');
  }

  // Do HTML last so that it always wins.
  return 'html';
}