function SystemConfigSubscriber::onConfigImporterValidateNotEmpty

Same name in other branches
  1. 9 core/modules/system/src/SystemConfigSubscriber.php \Drupal\system\SystemConfigSubscriber::onConfigImporterValidateNotEmpty()
  2. 8.9.x core/modules/system/src/SystemConfigSubscriber.php \Drupal\system\SystemConfigSubscriber::onConfigImporterValidateNotEmpty()
  3. 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 58

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();
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.