Newer
Older
* Contains \Drupal\Core\ContentNegotiation.
namespace Drupal\Core;
use Symfony\Component\HttpFoundation\Request;
/**
* Provides content negotation based upon query parameters.
*/
class ContentNegotiation {
Niklas Fiekas
committed
* Gets the normalized type of a request.
*
* The normalized type is a short, lowercase version of the format, such as
Niklas Fiekas
committed
* 'html', 'json' or 'atom'.
* @param \Symfony\Component\HttpFoundation\Request $request
* The request object from which to extract the content type.
Niklas Fiekas
committed
*
* @return string
Niklas Fiekas
committed
* The normalized type of a given request.
public function getContentType(Request $request) {
Niklas Fiekas
committed
// 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');
Angie Byron
committed
if ($request->isXmlHttpRequest()) {
return 'ajax';
}
Katherine Bailey
committed
// Do HTML last so that it always wins.
return 'html';