{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{module}}\{{ class }}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module}}\EventSubscriber;
{% endblock %}
{% block use_class %}
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\EventDispatcher\Event;
{% endblock %}
{% block class_declaration %}
/**
* Class {{ class }}.
*/
class {{ class }} implements EventSubscriberInterface {% endblock %}
{% block class_construct %}
/**
* Constructs a new {{ class }} object.
*/
public function __construct({{ servicesAsParameters(services)|join(', ') }}) {
{{ serviceClassInitialization(services) }}
}
{% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
{% for event_name, callback in events %}
$events['{{ event_name }}'] = ['{{ callback }}'];
{% endfor %}
return $events;
}
{% for event_name, callback in events %}
/**
* This method is called when the {{ event_name }} is dispatched.
*
* @param \Symfony\Component\EventDispatcher\Event $event
* The dispatched event.
*/
public function {{ callback }}(Event $event) {
\Drupal::messenger()->addMessage('Event {{ event_name }} thrown by Subscriber in module {{ module }}.', 'status', TRUE);
}
{% endfor %}
{% endblock %}