Same filename and directory in other branches
- 8.9.x core/modules/system/tests/modules/early_rendering_controller_test/src/TestDomainObjectViewSubscriber.php
- 9 core/modules/system/tests/modules/early_rendering_controller_test/src/TestDomainObjectViewSubscriber.php
Namespace
Drupal\early_rendering_controller_test
File
core/modules/system/tests/modules/early_rendering_controller_test/src/TestDomainObjectViewSubscriber.php
View source
<?php
namespace Drupal\early_rendering_controller_test;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\ViewEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class TestDomainObjectViewSubscriber implements EventSubscriberInterface {
public function onViewTestDomainObject(ViewEvent $event) {
$result = $event
->getControllerResult();
if ($result instanceof TestDomainObject) {
if ($result instanceof AttachmentsTestDomainObject) {
$event
->setResponse(new AttachmentsTestResponse('AttachmentsTestDomainObject'));
}
elseif ($result instanceof CacheableTestDomainObject) {
$event
->setResponse(new CacheableTestResponse('CacheableTestDomainObject'));
}
else {
$event
->setResponse(new Response('TestDomainObject'));
}
}
}
public static function getSubscribedEvents() : array {
$events[KernelEvents::VIEW][] = [
'onViewTestDomainObject',
];
return $events;
}
}
Classes