You are here

class TestDomainObjectViewSubscriber in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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

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 18
Contains \Drupal\early_rendering_controller_test\TestDomainObjectViewSubscriber.

Namespace

Drupal\early_rendering_controller_test
View source
class TestDomainObjectViewSubscriber implements EventSubscriberInterface {

  /**
   * Sets a response given a TestDomainObject instance.
   *
   * @param \Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $event
   *   The event to process.
   */
  public function onViewTestDomainObject(GetResponseForControllerResultEvent $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}
   */
  static function getSubscribedEvents() {
    $events[KernelEvents::VIEW][] = [
      'onViewTestDomainObject',
    ];
    return $events;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TestDomainObjectViewSubscriber::getSubscribedEvents static function Returns an array of event names this subscriber wants to listen to. Overrides EventSubscriberInterface::getSubscribedEvents
TestDomainObjectViewSubscriber::onViewTestDomainObject public function Sets a response given a TestDomainObject instance.