diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigImporterTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigImporterTest.php index 241c3396763ab6e78be850dd9766e8ada1b0f073..ec445c584a6ca7a306c11f2134d706c25419cf68 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigImporterTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigImporterTest.php @@ -90,10 +90,10 @@ function testEmptyImportFails() { try { $this->container->get('config.storage.staging')->deleteAll(); $this->configImporter->reset()->import(); - $this->assertFalse(FALSE, "ConfigImporterException not thrown, we didn't stop an empty import."); + $this->fail('ConfigImporterException thrown, successfully stopping an empty import.'); } catch (ConfigImporterException $e) { - $this->assertTrue(TRUE, 'ConfigImporterException thrown, successfully stopping an empty import.'); + $this->pass('ConfigImporterException thrown, successfully stopping an empty import.'); } } diff --git a/core/modules/system/lib/Drupal/system/SystemConfigSubscriber.php b/core/modules/system/lib/Drupal/system/SystemConfigSubscriber.php index 237473a1da09360b1650111bbeea48b8d7ed0447..d6e1fc6ac8bfd86cdbefddbc37f94255241f2869 100644 --- a/core/modules/system/lib/Drupal/system/SystemConfigSubscriber.php +++ b/core/modules/system/lib/Drupal/system/SystemConfigSubscriber.php @@ -1,4 +1,5 @@ <?php + /** * @file * Contains \Drupal\system\SystemConfigSubscriber. @@ -6,10 +7,8 @@ namespace Drupal\system; -use Drupal\Core\Config\Config; use Drupal\Core\Config\ConfigImporterEvent; use Drupal\Core\Config\ConfigImporterException; -use Drupal\Core\Config\ConfigEvent; use Drupal\Core\Config\StorageDispatcher; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -19,18 +18,26 @@ class SystemConfigSubscriber implements EventSubscriberInterface { /** - * Implements EventSubscriberInterface::getSubscribedEvents(). + * {@inheritdoc} */ static function getSubscribedEvents() { $events['config.importer.validate'][] = array('onConfigImporterValidate', 20); return $events; } + /** + * Checks that the import source storage is not empty. + * + * @param ConfigImporterEvent $event + * The config import event. + * + * @throws \Drupal\Core\Config\ConfigImporterException + * Exception thrown if the source storage is empty. + */ public function onConfigImporterValidate(ConfigImporterEvent $event) { - $importer = $event->getConfigImporter(); - $importList = $importer->getStorageComparer()->getSourceStorage()->listAll(); - if (empty($importerList)) { - throw new ConfigImporterException("This import will delete all your active configuration, I'm bailing out now."); + $importList = $event->getConfigImporter()->getStorageComparer()->getSourceStorage()->listAll(); + if (empty($importList)) { + throw new ConfigImporterException('This import is empty and if applied would delete all of your configuration, so has been rejected.'); } } } diff --git a/core/modules/system/system.services.yml b/core/modules/system/system.services.yml index 54e5b1149317a6ab1c15bc1529ff47b9730a10ba..179bb27f34830a89678b566638b0aacb5c102741 100644 --- a/core/modules/system/system.services.yml +++ b/core/modules/system/system.services.yml @@ -20,3 +20,7 @@ services: arguments: ['@batch.storage'] tags: - { name: theme_negotiator, priority: 1000 } + system.config_subscriber: + class: Drupal\system\SystemConfigSubscriber + tags: + - { name: event_subscriber }