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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 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.