comparison vendor/chi-teck/drupal-code-generator/templates/d8/service/event-subscriber.twig @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children a9cd425dd02b
comparison
equal deleted inserted replaced
-1:000000000000 0:c75dbcec494b
1 <?php
2
3 namespace Drupal\{{ machine_name }}\EventSubscriber;
4
5 use Drupal\Core\Session\AccountProxyInterface;
6 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
7 use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
8 use Symfony\Component\HttpKernel\Event\GetResponseEvent;
9 use Symfony\Component\HttpKernel\KernelEvents;
10
11 /**
12 * {{ name }} event subscriber.
13 */
14 class {{ class }} implements EventSubscriberInterface {
15
16 /**
17 * Current logged in user.
18 *
19 * @var \Drupal\Core\Session\AccountProxyInterface
20 */
21 protected $currentUser;
22
23 /**
24 * Constructs event subscriber.
25 *
26 * @param \Drupal\Core\Session\AccountProxyInterface $current_user
27 * Current logged in user.
28 */
29 public function __construct(AccountProxyInterface $current_user) {
30 $this->currentUser = $current_user;
31 }
32
33 /**
34 * Kernel request event handler.
35 *
36 * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
37 * Response event.
38 */
39 public function onKernelRequest(GetResponseEvent $event) {
40 drupal_set_message(__FUNCTION__);
41 }
42
43 /**
44 * Kernel response event handler.
45 *
46 * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
47 * Response event.
48 */
49 public function onKernelResponse(FilterResponseEvent $event) {
50 drupal_set_message(__FUNCTION__);
51 }
52
53 /**
54 * {@inheritdoc}
55 */
56 public static function getSubscribedEvents() {
57 return [
58 KernelEvents::REQUEST => ['onKernelRequest'],
59 KernelEvents::RESPONSE => ['onKernelResponse'],
60 ];
61 }
62
63 }