function NegotiationMiddleware::getContentType

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php \Drupal\Core\StackMiddleware\NegotiationMiddleware::getContentType()
  2. 8.9.x core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php \Drupal\Core\StackMiddleware\NegotiationMiddleware::getContentType()
  3. 10 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
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 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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.