You are here

public function SystemConfigSubscriber::onConfigImporterValidateNotEmpty in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/system/src/SystemConfigSubscriber.php \Drupal\system\SystemConfigSubscriber::onConfigImporterValidateNotEmpty()
  2. 10 core/modules/system/src/SystemConfigSubscriber.php \Drupal\system\SystemConfigSubscriber::onConfigImporterValidateNotEmpty()

Checks that the configuration synchronization is valid.

This event listener prevents deleting all configuration. If there is nothing to import then event propagation is stopped because there is no config import to validate.

Parameters

\Drupal\Core\Config\ConfigImporterEvent $event: The config import event.

File

core/modules/system/src/SystemConfigSubscriber.php, line 57

Class

SystemConfigSubscriber
System Config subscriber.

Namespace

Drupal\system

Code

public function onConfigImporterValidateNotEmpty(ConfigImporterEvent $event) {
  $importList = $event
    ->getConfigImporter()
    ->getStorageComparer()
    ->getSourceStorage()
    ->listAll();
  if (empty($importList)) {
    $event
      ->getConfigImporter()
      ->logError($this
      ->t('This import is empty and if applied would delete all of your configuration, so has been rejected.'));
    $event
      ->stopPropagation();
  }
}