1. 8.0.x core/lib/Drupal/Core/EventSubscriber/AcceptNegotiation406.php AcceptNegotiation406
  2. 8.1.x core/lib/Drupal/Core/EventSubscriber/AcceptNegotiation406.php AcceptNegotiation406
  3. 8.2.x core/lib/Drupal/Core/EventSubscriber/AcceptNegotiation406.php AcceptNegotiation406
  4. 8.3.x core/lib/Drupal/Core/EventSubscriber/AcceptNegotiation406.php AcceptNegotiation406

View subscriber rendering a 406 if we could not route or render a request.

@todo fix or replace this in https://www.drupal.org/node/2364011

Hierarchy

Expanded class hierarchy of AcceptNegotiation406

1 string reference to 'AcceptNegotiation406'
core.services.yml in core/core.services.yml
core/core.services.yml

File

core/lib/Drupal/Core/EventSubscriber/AcceptNegotiation406.php, line 15

Namespace

Drupal\Core\EventSubscriber
View source
class AcceptNegotiation406 implements EventSubscriberInterface {

  /**
   * Throws an HTTP 406 error if we get this far, which we normally shouldn't.
   *
   * @param \Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $event
   *   The event to process.
   */
  public function onViewDetect406(GetResponseForControllerResultEvent $event) {
    $request = $event
      ->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][] = [
      'onViewDetect406',
      -10,
    ];
    return $events;
  }

}

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description Overrides
AcceptNegotiation406::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to. Overrides EventSubscriberInterface::getSubscribedEvents
AcceptNegotiation406::onViewDetect406 public function Throws an HTTP 406 error if we get this far, which we normally shouldn't.