Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / config / tests / config_events_test / src / EventSubscriber.php
1 <?php
2
3 namespace Drupal\config_events_test;
4
5 use Drupal\Core\Config\ConfigCrudEvent;
6 use Drupal\Core\Config\ConfigEvents;
7 use Drupal\Core\State\StateInterface;
8 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
9
10 class EventSubscriber implements EventSubscriberInterface {
11
12   /**
13    * The state key value store.
14    *
15    * @var \Drupal\Core\State\StateInterface
16    */
17   protected $state;
18
19   /**
20    * Constructs the Event Subscriber object.
21    *
22    * @param \Drupal\Core\State\StateInterface $state
23    *   The state key value store.
24    */
25   public function __construct(StateInterface $state) {
26     $this->state = $state;
27   }
28
29   /**
30    * Reacts to config event.
31    *
32    * @param \Drupal\Core\Config\ConfigCrudEvent $event
33    *   The configuration event.
34    * @param string $name
35    *   The event name.
36    */
37   public function configEventRecorder(ConfigCrudEvent $event, $name) {
38     $config = $event->getConfig();
39     $this->state->set('config_events_test.event', [
40       'event_name' => $name,
41       'current_config_data' => $config->get(),
42       'original_config_data' => $config->getOriginal(),
43       'raw_config_data' => $config->getRawData(),
44     ]);
45   }
46
47   /**
48    * {@inheritdoc}
49    */
50   public static function getSubscribedEvents() {
51     $events[ConfigEvents::SAVE][] = ['configEventRecorder'];
52     $events[ConfigEvents::DELETE][] = ['configEventRecorder'];
53     $events[ConfigEvents::RENAME][] = ['configEventRecorder'];
54     return $events;
55   }
56
57 }