3 namespace Drupal\config_events_test;
5 use Drupal\Core\Config\ConfigCrudEvent;
6 use Drupal\Core\Config\ConfigEvents;
7 use Drupal\Core\State\StateInterface;
8 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
10 class EventSubscriber implements EventSubscriberInterface {
13 * The state key value store.
15 * @var \Drupal\Core\State\StateInterface
20 * Constructs the Event Subscriber object.
22 * @param \Drupal\Core\State\StateInterface $state
23 * The state key value store.
25 public function __construct(StateInterface $state) {
26 $this->state = $state;
30 * Reacts to config event.
32 * @param \Drupal\Core\Config\ConfigCrudEvent $event
33 * The configuration event.
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(),
50 public static function getSubscribedEvents() {
51 $events[ConfigEvents::SAVE][] = ['configEventRecorder'];
52 $events[ConfigEvents::DELETE][] = ['configEventRecorder'];
53 $events[ConfigEvents::RENAME][] = ['configEventRecorder'];