class HtmlResponseSubscriber
Same name in other branches
- 9 core/lib/Drupal/Core/EventSubscriber/HtmlResponseSubscriber.php \Drupal\Core\EventSubscriber\HtmlResponseSubscriber
- 8.9.x core/lib/Drupal/Core/EventSubscriber/HtmlResponseSubscriber.php \Drupal\Core\EventSubscriber\HtmlResponseSubscriber
- 10 core/lib/Drupal/Core/EventSubscriber/HtmlResponseSubscriber.php \Drupal\Core\EventSubscriber\HtmlResponseSubscriber
Response subscriber to handle HTML responses.
Hierarchy
- class \Drupal\Core\EventSubscriber\HtmlResponseSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of HtmlResponseSubscriber
File
-
core/
lib/ Drupal/ Core/ EventSubscriber/ HtmlResponseSubscriber.php, line 14
Namespace
Drupal\Core\EventSubscriberView 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\ResponseEvent $event
* The event to process.
*/
public function onRespond(ResponseEvent $event) {
$response = $event->getResponse();
if (!$response instanceof HtmlResponse) {
return;
}
$event->setResponse($this->htmlResponseAttachmentsProcessor
->processAttachments($response));
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() : array {
$events[KernelEvents::RESPONSE][] = [
'onRespond',
];
return $events;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
HtmlResponseSubscriber::$htmlResponseAttachmentsProcessor | protected | property | The HTML response attachments processor service. |
HtmlResponseSubscriber::getSubscribedEvents | public static | function | |
HtmlResponseSubscriber::onRespond | public | function | Processes attachments for HtmlResponse responses. |
HtmlResponseSubscriber::__construct | public | function | Constructs a HtmlResponseSubscriber object. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.