class TestDomainObjectViewSubscriber in Drupal 10
Same name and namespace in other branches
- 8 core/modules/system/tests/modules/early_rendering_controller_test/src/TestDomainObjectViewSubscriber.php \Drupal\early_rendering_controller_test\TestDomainObjectViewSubscriber
- 9 core/modules/system/tests/modules/early_rendering_controller_test/src/TestDomainObjectViewSubscriber.php \Drupal\early_rendering_controller_test\TestDomainObjectViewSubscriber
View subscriber for turning TestDomainObject objects into Response objects.
Hierarchy
- class \Drupal\early_rendering_controller_test\TestDomainObjectViewSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of TestDomainObjectViewSubscriber
1 string reference to 'TestDomainObjectViewSubscriber'
- early_rendering_controller_test.services.yml in core/
modules/ system/ tests/ modules/ early_rendering_controller_test/ early_rendering_controller_test.services.yml - core/modules/system/tests/modules/early_rendering_controller_test/early_rendering_controller_test.services.yml
1 service uses TestDomainObjectViewSubscriber
- test_domain_object.view_subscriber in core/
modules/ system/ tests/ modules/ early_rendering_controller_test/ early_rendering_controller_test.services.yml - Drupal\early_rendering_controller_test\TestDomainObjectViewSubscriber
File
- core/
modules/ system/ tests/ modules/ early_rendering_controller_test/ src/ TestDomainObjectViewSubscriber.php, line 13
Namespace
Drupal\early_rendering_controller_testView source
class TestDomainObjectViewSubscriber implements EventSubscriberInterface {
/**
* Sets a response given a TestDomainObject instance.
*
* @param \Symfony\Component\HttpKernel\Event\ViewEvent $event
* The event to process.
*/
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'));
}
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() : array {
$events[KernelEvents::VIEW][] = [
'onViewTestDomainObject',
];
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
TestDomainObjectViewSubscriber:: |
public static | function | ||
TestDomainObjectViewSubscriber:: |
public | function | Sets a response given a TestDomainObject instance. |