ConfigSubscriber.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace Drupal\config;
  3. use Drupal\Core\Config\ConfigEvents;
  4. use Drupal\Core\Config\ConfigImporterEvent;
  5. use Drupal\Core\Config\ConfigImportValidateEventSubscriberBase;
  6. /**
  7. * Config subscriber.
  8. */
  9. class ConfigSubscriber extends ConfigImportValidateEventSubscriberBase {
  10. /**
  11. * Checks that the Configuration module is not being uninstalled.
  12. *
  13. * @param \Drupal\Core\Config\ConfigImporterEvent $event
  14. * The config import event.
  15. */
  16. public function onConfigImporterValidate(ConfigImporterEvent $event) {
  17. $importer = $event->getConfigImporter();
  18. $core_extension = $importer->getStorageComparer()->getSourceStorage()->read('core.extension');
  19. if (!isset($core_extension['module']['config'])) {
  20. $importer->logError($this->t('Can not uninstall the Configuration module as part of a configuration synchronization through the user interface.'));
  21. }
  22. }
  23. /**
  24. * {@inheritdoc}
  25. */
  26. public static function getSubscribedEvents() {
  27. $events[ConfigEvents::IMPORT_VALIDATE][] = ['onConfigImporterValidate', 20];
  28. return $events;
  29. }
  30. }