HtmlResponseSubscriber.php in Drupal 10
File
core/lib/Drupal/Core/EventSubscriber/HtmlResponseSubscriber.php
View source
<?php
namespace Drupal\Core\EventSubscriber;
use Drupal\Core\Render\HtmlResponse;
use Drupal\Core\Render\AttachmentsResponseProcessorInterface;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class HtmlResponseSubscriber implements EventSubscriberInterface {
protected $htmlResponseAttachmentsProcessor;
public function __construct(AttachmentsResponseProcessorInterface $html_response_attachments_processor) {
$this->htmlResponseAttachmentsProcessor = $html_response_attachments_processor;
}
public function onRespond(ResponseEvent $event) {
$response = $event
->getResponse();
if (!$response instanceof HtmlResponse) {
return;
}
$event
->setResponse($this->htmlResponseAttachmentsProcessor
->processAttachments($response));
}
public static function getSubscribedEvents() : array {
$events[KernelEvents::RESPONSE][] = [
'onRespond',
];
return $events;
}
}