You are here

class HtmlResponseSubscriber in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/EventSubscriber/HtmlResponseSubscriber.php \Drupal\Core\EventSubscriber\HtmlResponseSubscriber

Response subscriber to handle HTML responses.

Hierarchy

Expanded class hierarchy of HtmlResponseSubscriber

1 string reference to 'HtmlResponseSubscriber'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses HtmlResponseSubscriber
html_response.subscriber in core/core.services.yml
Drupal\Core\EventSubscriber\HtmlResponseSubscriber

File

core/lib/Drupal/Core/EventSubscriber/HtmlResponseSubscriber.php, line 19
Contains \Drupal\Core\EventSubscriber\HtmlResponseSubscriber.

Namespace

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

  /**
   * The HTML response attachments processor service.
   *
   * @var \Drupal\Core\Render\AttachmentsResponseProcessorInterface
   */
  protected $htmlResponseAttachmentsProcessor;

  /**
   * Constructs a HtmlResponseSubscriber object.
   *
   * @param \Drupal\Core\Render\AttachmentsResponseProcessorInterface $html_response_attachments_processor
   *   The HTML response attachments processor service.
   */
  public function __construct(AttachmentsResponseProcessorInterface $html_response_attachments_processor) {
    $this->htmlResponseAttachmentsProcessor = $html_response_attachments_processor;
  }

  /**
   * Processes attachments for HtmlResponse responses.
   *
   * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
   *   The event to process.
   */
  public function onRespond(FilterResponseEvent $event) {
    $response = $event
      ->getResponse();
    if (!$response instanceof HtmlResponse) {
      return;
    }
    $event
      ->setResponse($this->htmlResponseAttachmentsProcessor
      ->processAttachments($response));
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[KernelEvents::RESPONSE][] = [
      'onRespond',
    ];
    return $events;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
HtmlResponseSubscriber::$htmlResponseAttachmentsProcessor protected property The HTML response attachments processor service.
HtmlResponseSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to. Overrides EventSubscriberInterface::getSubscribedEvents
HtmlResponseSubscriber::onRespond public function Processes attachments for HtmlResponse responses.
HtmlResponseSubscriber::__construct public function Constructs a HtmlResponseSubscriber object.