class FormTestEventSubscriber in Drupal 10
Same name and namespace in other branches
- 8 core/modules/system/tests/modules/form_test/src/EventSubscriber/FormTestEventSubscriber.php \Drupal\form_test\EventSubscriber\FormTestEventSubscriber
- 9 core/modules/system/tests/modules/form_test/src/EventSubscriber/FormTestEventSubscriber.php \Drupal\form_test\EventSubscriber\FormTestEventSubscriber
Test event subscriber to add new attributes to the request.
Hierarchy
- class \Drupal\form_test\EventSubscriber\FormTestEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of FormTestEventSubscriber
1 string reference to 'FormTestEventSubscriber'
- form_test.services.yml in core/
modules/ system/ tests/ modules/ form_test/ form_test.services.yml - core/modules/system/tests/modules/form_test/form_test.services.yml
1 service uses FormTestEventSubscriber
- form_test.event_subscriber in core/
modules/ system/ tests/ modules/ form_test/ form_test.services.yml - Drupal\form_test\EventSubscriber\FormTestEventSubscriber
File
- core/
modules/ system/ tests/ modules/ form_test/ src/ EventSubscriber/ FormTestEventSubscriber.php, line 13
Namespace
Drupal\form_test\EventSubscriberView source
class FormTestEventSubscriber implements EventSubscriberInterface {
/**
* Adds custom attributes to the request object.
*
* @param \Symfony\Component\HttpKernel\Event\RequestEvent $event
* The kernel request event.
*/
public function onKernelRequest(RequestEvent $event) {
$request = $event
->getRequest();
$request->attributes
->set('custom_attributes', 'custom_value');
$request->attributes
->set('request_attribute', 'request_value');
}
/**
* Adds custom headers to the response.
*
* @param \Symfony\Component\HttpKernel\Event\ResponseEvent $event
* The kernel response event.
*/
public function onKernelResponse(ResponseEvent $event) {
$response = $event
->getResponse();
$response->headers
->set('X-Form-Test-Response-Event', 'invoked');
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() : array {
$events[KernelEvents::REQUEST][] = [
'onKernelRequest',
];
$events[KernelEvents::RESPONSE][] = [
'onKernelResponse',
];
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FormTestEventSubscriber:: |
public static | function | ||
FormTestEventSubscriber:: |
public | function | Adds custom attributes to the request object. | |
FormTestEventSubscriber:: |
public | function | Adds custom headers to the response. |