class FormTestEventSubscriber

Test event subscriber to add new attributes to the request.

Hierarchy

Expanded class hierarchy of FormTestEventSubscriber

1 string reference to 'FormTestEventSubscriber'
form_test.services.yml in drupal/core/modules/system/tests/modules/form_test/form_test.services.yml
drupal/core/modules/system/tests/modules/form_test/form_test.services.yml
1 service uses FormTestEventSubscriber

File

drupal/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/EventSubscriber/FormTestEventSubscriber.php, line 17
Contains \Drupal\form_test\EventSubscriber\FormTestEventSubscriber.

Namespace

Drupal\form_test\EventSubscriber
View source
class FormTestEventSubscriber implements EventSubscriberInterface {

  /**
   * Adds custom attributes to the request object.
   *
   * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
   *   The kernel request event.
   */
  public function onKernelRequest(GetResponseEvent $event) {
    $request = $event
      ->getRequest();
    $request->attributes
      ->set('custom_attributes', 'custom_value');
    $request->attributes
      ->set('request_attribute', 'request_value');
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[KernelEvents::REQUEST][] = array(
      'onKernelRequest',
    );
    return $events;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FormTestEventSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to. Overrides EventSubscriberInterface::getSubscribedEvents
FormTestEventSubscriber::onKernelRequest public function Adds custom attributes to the request object.