Same filename and directory in other branches
- 8.9.x core/lib/Drupal/Core/EventSubscriber/HtmlResponsePlaceholderStrategySubscriber.php
- 9 core/lib/Drupal/Core/EventSubscriber/HtmlResponsePlaceholderStrategySubscriber.php
Namespace
Drupal\Core\EventSubscriber
File
core/lib/Drupal/Core/EventSubscriber/HtmlResponsePlaceholderStrategySubscriber.php
View source
<?php
namespace Drupal\Core\EventSubscriber;
use Drupal\Core\Render\HtmlResponse;
use Drupal\Core\Render\Placeholder\PlaceholderStrategyInterface;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class HtmlResponsePlaceholderStrategySubscriber implements EventSubscriberInterface {
protected $placeholderStrategy;
public function __construct(PlaceholderStrategyInterface $placeholder_strategy) {
$this->placeholderStrategy = $placeholder_strategy;
}
public function onRespond(ResponseEvent $event) {
$response = $event
->getResponse();
if (!$response instanceof HtmlResponse) {
return;
}
$attachments = $response
->getAttachments();
if (empty($attachments['placeholders'])) {
return;
}
$attachments['placeholders'] = $this->placeholderStrategy
->processPlaceholders($attachments['placeholders']);
$response
->setAttachments($attachments);
}
public static function getSubscribedEvents() : array {
$events[KernelEvents::RESPONSE][] = [
'onRespond',
5,
];
return $events;
}
}
Classes