protected DefaultExceptionSubscriber::getFormat(Request $request)
Gets the error-relevant format from the request.
Parameters
\Symfony\Component\HttpFoundation\Request $request: The request object.
Return value
string The format as which to treat the exception.
File
- core/lib/Drupal/Core/EventSubscriber/DefaultExceptionSubscriber.php, line 212
 
Class
- DefaultExceptionSubscriber
 - Last-chance handler for exceptions.
 
Namespace
Drupal\Core\EventSubscriber
Code
protected function getFormat(Request $request) {
  $format = $request->query->get(MainContentViewSubscriber::WRAPPER_FORMAT, $request->getRequestFormat());
  // These are all JSON errors for our purposes. Any special handling for
  // them can/should happen in earlier listeners if desired.
  if (in_array($format, ['drupal_modal', 'drupal_dialog', 'drupal_ajax'])) {
    $format = 'json';
  }
  // Make an educated guess that any Accept header type that includes "json"
  // can probably handle a generic JSON response for errors. As above, for
  // any format this doesn't catch or that wants custom handling should
  // register its own exception listener.
  foreach ($request->getAcceptableContentTypes() as $mime) {
    if (strpos($mime, 'html') === FALSE && strpos($mime, 'json') !== FALSE) {
      $format = 'json';
    }
  }
  return $format;
}
Please login to continue.