X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Flib%2FDrupal%2FCore%2FEventSubscriber%2FRenderArrayNonHtmlSubscriber.php;fp=web%2Fcore%2Flib%2FDrupal%2FCore%2FEventSubscriber%2FRenderArrayNonHtmlSubscriber.php;h=afb9ef5b031c03eeb174d5ef50caa72b7e536d9f;hp=0000000000000000000000000000000000000000;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/web/core/lib/Drupal/Core/EventSubscriber/RenderArrayNonHtmlSubscriber.php b/web/core/lib/Drupal/Core/EventSubscriber/RenderArrayNonHtmlSubscriber.php new file mode 100644 index 000000000..afb9ef5b0 --- /dev/null +++ b/web/core/lib/Drupal/Core/EventSubscriber/RenderArrayNonHtmlSubscriber.php @@ -0,0 +1,42 @@ +getRequest(); + $result = $event->getControllerResult(); + + // If this is a render array then we assume that the router went with the + // generic controller and not one with a format. If the format requested is + // not HTML though, we can also assume that the requested format is invalid + // so we provide a 406 response. + if (is_array($result) && $request->getRequestFormat() !== 'html') { + throw new NotAcceptableHttpException('Not acceptable format: ' . $request->getRequestFormat()); + } + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() { + $events[KernelEvents::VIEW][] = ['onRespond', -10]; + return $events; + } + +}