3 namespace Drupal\Core\EventSubscriber;
5 use Drupal\Core\Config\ConfigEvents;
6 use Drupal\Core\Config\ConfigManagerInterface;
7 use Drupal\Core\Config\StorageInterface;
8 use Drupal\Core\Config\ConfigImporterEvent;
9 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
12 * Create a snapshot when config is imported.
14 class ConfigSnapshotSubscriber implements EventSubscriberInterface {
17 * The configuration manager.
19 * @var \Drupal\Core\Config\ConfigManagerInterface
21 protected $configManager;
24 * The source storage used to discover configuration changes.
26 * @var \Drupal\Core\Config\StorageInterface
28 protected $sourceStorage;
31 * The snapshot storage used to write configuration changes.
33 * @var \Drupal\Core\Config\StorageInterface
35 protected $snapshotStorage;
38 * Constructs the ConfigSnapshotSubscriber object.
40 * @param \Drupal\Core\Config\StorageInterface $source_storage
41 * The source storage used to discover configuration changes.
42 * @param \Drupal\Core\Config\StorageInterface $snapshot_storage
43 * The snapshot storage used to write configuration changes.
45 public function __construct(ConfigManagerInterface $config_manager, StorageInterface $source_storage, StorageInterface $snapshot_storage) {
46 $this->configManager = $config_manager;
47 $this->sourceStorage = $source_storage;
48 $this->snapshotStorage = $snapshot_storage;
52 * Creates a config snapshot.
54 * @param \Drupal\Core\Config\ConfigImporterEvent $event
55 * The Event to process.
57 public function onConfigImporterImport(ConfigImporterEvent $event) {
58 $this->configManager->createSnapshot($this->sourceStorage, $this->snapshotStorage);
62 * Registers the methods in this class that should be listeners.
65 * An array of event listener definitions.
67 public static function getSubscribedEvents() {
68 $events[ConfigEvents::IMPORT][] = ['onConfigImporterImport', 40];