diff core/modules/config/src/ConfigSubscriber.php @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/modules/config/src/ConfigSubscriber.php	Thu Jul 05 14:24:15 2018 +0000
@@ -0,0 +1,41 @@
+<?php
+
+namespace Drupal\config;
+
+use Drupal\Core\Config\ConfigEvents;
+use Drupal\Core\Config\ConfigImporterEvent;
+use Drupal\Core\Config\ConfigImportValidateEventSubscriberBase;
+
+/**
+ * Config subscriber.
+ */
+class ConfigSubscriber extends ConfigImportValidateEventSubscriberBase {
+
+  /**
+   * Checks that the Configuration module is not being uninstalled.
+   *
+   * @param \Drupal\Core\Config\ConfigImporterEvent $event
+   *   The config import event.
+   */
+  public function onConfigImporterValidate(ConfigImporterEvent $event) {
+    // Make sure config syncs performed via the Config UI don't break, but
+    // don't worry about syncs initiated via the command line.
+    if (PHP_SAPI === 'cli') {
+      return;
+    }
+    $importer = $event->getConfigImporter();
+    $core_extension = $importer->getStorageComparer()->getSourceStorage()->read('core.extension');
+    if (!isset($core_extension['module']['config'])) {
+      $importer->logError($this->t('Can not uninstall the Configuration module as part of a configuration synchronization through the user interface.'));
+    }
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function getSubscribedEvents() {
+    $events[ConfigEvents::IMPORT_VALIDATE][] = ['onConfigImporterValidate', 20];
+    return $events;
+  }
+
+}