function TestDomainObjectViewSubscriber::onViewTestDomainObject

Same name in other branches
  1. 9 core/modules/system/tests/modules/early_rendering_controller_test/src/TestDomainObjectViewSubscriber.php \Drupal\early_rendering_controller_test\TestDomainObjectViewSubscriber::onViewTestDomainObject()
  2. 8.9.x core/modules/system/tests/modules/early_rendering_controller_test/src/TestDomainObjectViewSubscriber.php \Drupal\early_rendering_controller_test\TestDomainObjectViewSubscriber::onViewTestDomainObject()
  3. 11.x core/modules/system/tests/modules/early_rendering_controller_test/src/TestDomainObjectViewSubscriber.php \Drupal\early_rendering_controller_test\TestDomainObjectViewSubscriber::onViewTestDomainObject()

Sets a response given a TestDomainObject instance.

Parameters

\Symfony\Component\HttpKernel\Event\ViewEvent $event: The event to process.

File

core/modules/system/tests/modules/early_rendering_controller_test/src/TestDomainObjectViewSubscriber.php, line 21

Class

TestDomainObjectViewSubscriber
View subscriber for turning TestDomainObject objects into Response objects.

Namespace

Drupal\early_rendering_controller_test

Code

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'));
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.