Drupal 8.0.0 beta 12. More info: https://www.drupal.org/node/2514176
This commit is contained in:
commit
9921556621
13277 changed files with 1459781 additions and 0 deletions
47
core/lib/Drupal/Core/ContentNegotiation.php
Normal file
47
core/lib/Drupal/Core/ContentNegotiation.php
Normal file
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\ContentNegotiation.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Provides content negotation based upon query parameters.
|
||||
*/
|
||||
class ContentNegotiation {
|
||||
|
||||
/**
|
||||
* Gets the normalized type of a request.
|
||||
*
|
||||
* The normalized type is a short, lowercase version of the format, such as
|
||||
* 'html', 'json' or 'atom'.
|
||||
*
|
||||
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||
* The request object from which to extract the content type.
|
||||
*
|
||||
* @return string
|
||||
* The normalized type of a given request.
|
||||
*/
|
||||
public 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');
|
||||
}
|
||||
|
||||
if ($request->isXmlHttpRequest()) {
|
||||
return 'ajax';
|
||||
}
|
||||
|
||||
// Do HTML last so that it always wins.
|
||||
return 'html';
|
||||
}
|
||||
}
|
Reference in a new issue