class ExampleEventSubscriber in Webform Node Element 8
Class ExampleEventSubscriber.
This class shows how to use events to modify the node and display mode that the webform_node_element displays.
@package Drupal\webform_node_element_example
Hierarchy
- class \Drupal\webform_node_element_example\EventSubscriber\ExampleEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of ExampleEventSubscriber
1 string reference to 'ExampleEventSubscriber'
- webform_node_element_example.services.yml in modules/
webform_node_element_example/ webform_node_element_example.services.yml - modules/webform_node_element_example/webform_node_element_example.services.yml
1 service uses ExampleEventSubscriber
- webform_node_element_example.example_event_subscriber in modules/
webform_node_element_example/ webform_node_element_example.services.yml - Drupal\webform_node_element_example\EventSubscriber\ExampleEventSubscriber
File
- modules/
webform_node_element_example/ src/ EventSubscriber/ ExampleEventSubscriber.php, line 16
Namespace
Drupal\webform_node_element_example\EventSubscriberView source
class ExampleEventSubscriber implements EventSubscriberInterface {
/**
* Set the events that we want to subscribe to.
*
* Tell Drupal that we're interested in subscribing to the
* webform_node_element prerender event.
*
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[WebformNodeElementPreRender::PRERENDER][] = [
'onWebformNodeElementPreRender',
800,
];
return $events;
}
/**
* This is called whenever the webform_node_element prerender event occurs.
*
* For example purposes we tell the element to display node 1 using the
* 'teaser' display mode.
*
* @param \WebformNodeElementPreRender $event
* The event that triggered this callback.
*/
public function onWebformNodeElementPreRender(WebformNodeElementPreRender $event) {
$event
->setNid(1);
$event
->setDisplayMode('teaser');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ExampleEventSubscriber:: |
public static | function | Set the events that we want to subscribe to. | |
ExampleEventSubscriber:: |
public | function | This is called whenever the webform_node_element prerender event occurs. |