You are here

public function TestDomainObjectViewSubscriber::onViewTestDomainObject in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/system/tests/modules/early_rendering_controller_test/src/TestDomainObjectViewSubscriber.php \Drupal\early_rendering_controller_test\TestDomainObjectViewSubscriber::onViewTestDomainObject()
  2. 9 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'));
    }
  }
}