Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Core\EventSubscriber;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Core\Config\ConfigEvents;
|
Chris@0
|
6 use Drupal\Core\Config\ConfigManagerInterface;
|
Chris@0
|
7 use Drupal\Core\Config\StorageInterface;
|
Chris@0
|
8 use Drupal\Core\Config\ConfigImporterEvent;
|
Chris@0
|
9 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
Chris@0
|
10
|
Chris@0
|
11 /**
|
Chris@0
|
12 * Create a snapshot when config is imported.
|
Chris@0
|
13 */
|
Chris@0
|
14 class ConfigSnapshotSubscriber implements EventSubscriberInterface {
|
Chris@0
|
15
|
Chris@0
|
16 /**
|
Chris@0
|
17 * The configuration manager.
|
Chris@0
|
18 *
|
Chris@0
|
19 * @var \Drupal\Core\Config\ConfigManagerInterface
|
Chris@0
|
20 */
|
Chris@0
|
21 protected $configManager;
|
Chris@0
|
22
|
Chris@0
|
23 /**
|
Chris@0
|
24 * The source storage used to discover configuration changes.
|
Chris@0
|
25 *
|
Chris@0
|
26 * @var \Drupal\Core\Config\StorageInterface
|
Chris@0
|
27 */
|
Chris@0
|
28 protected $sourceStorage;
|
Chris@0
|
29
|
Chris@0
|
30 /**
|
Chris@0
|
31 * The snapshot storage used to write configuration changes.
|
Chris@0
|
32 *
|
Chris@0
|
33 * @var \Drupal\Core\Config\StorageInterface
|
Chris@0
|
34 */
|
Chris@0
|
35 protected $snapshotStorage;
|
Chris@0
|
36
|
Chris@0
|
37 /**
|
Chris@0
|
38 * Constructs the ConfigSnapshotSubscriber object.
|
Chris@0
|
39 *
|
Chris@12
|
40 * @param \Drupal\Core\Config\StorageInterface $source_storage
|
Chris@0
|
41 * The source storage used to discover configuration changes.
|
Chris@12
|
42 * @param \Drupal\Core\Config\StorageInterface $snapshot_storage
|
Chris@0
|
43 * The snapshot storage used to write configuration changes.
|
Chris@0
|
44 */
|
Chris@0
|
45 public function __construct(ConfigManagerInterface $config_manager, StorageInterface $source_storage, StorageInterface $snapshot_storage) {
|
Chris@0
|
46 $this->configManager = $config_manager;
|
Chris@0
|
47 $this->sourceStorage = $source_storage;
|
Chris@0
|
48 $this->snapshotStorage = $snapshot_storage;
|
Chris@0
|
49 }
|
Chris@0
|
50
|
Chris@0
|
51 /**
|
Chris@0
|
52 * Creates a config snapshot.
|
Chris@0
|
53 *
|
Chris@0
|
54 * @param \Drupal\Core\Config\ConfigImporterEvent $event
|
Chris@0
|
55 * The Event to process.
|
Chris@0
|
56 */
|
Chris@0
|
57 public function onConfigImporterImport(ConfigImporterEvent $event) {
|
Chris@0
|
58 $this->configManager->createSnapshot($this->sourceStorage, $this->snapshotStorage);
|
Chris@0
|
59 }
|
Chris@0
|
60
|
Chris@0
|
61 /**
|
Chris@0
|
62 * Registers the methods in this class that should be listeners.
|
Chris@0
|
63 *
|
Chris@0
|
64 * @return array
|
Chris@0
|
65 * An array of event listener definitions.
|
Chris@0
|
66 */
|
Chris@0
|
67 public static function getSubscribedEvents() {
|
Chris@0
|
68 $events[ConfigEvents::IMPORT][] = ['onConfigImporterImport', 40];
|
Chris@0
|
69 return $events;
|
Chris@0
|
70 }
|
Chris@0
|
71
|
Chris@0
|
72 }
|