function ConfigSync::submitForm

Same name in other branches
  1. 9 core/modules/config/src/Form/ConfigSync.php \Drupal\config\Form\ConfigSync::submitForm()
  2. 8.9.x core/modules/config/src/Form/ConfigSync.php \Drupal\config\Form\ConfigSync::submitForm()
  3. 10 core/modules/config/src/Form/ConfigSync.php \Drupal\config\Form\ConfigSync::submitForm()

Overrides FormInterface::submitForm

File

core/modules/config/src/Form/ConfigSync.php, line 264

Class

ConfigSync
Construct the storage changes in a configuration synchronization form.

Namespace

Drupal\config\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
    $config_importer = new ConfigImporter($form_state->get('storage_comparer'), $this->eventDispatcher, $this->configManager, $this->lock, $this->typedConfigManager, $this->moduleHandler, $this->moduleInstaller, $this->themeHandler, $this->getStringTranslation(), $this->moduleExtensionList, $this->themeExtensionList);
    if ($config_importer->alreadyImporting()) {
        $this->messenger()
            ->addStatus($this->t('Another request may be synchronizing configuration already.'));
    }
    else {
        try {
            $sync_steps = $config_importer->initialize();
            $batch_builder = (new BatchBuilder())->setTitle($this->t('Synchronizing configuration'))
                ->setFinishCallback([
                ConfigImporterBatch::class,
                'finish',
            ])
                ->setInitMessage($this->t('Starting configuration synchronization.'))
                ->setProgressMessage($this->t('Completed step @current of @total.'))
                ->setErrorMessage($this->t('Configuration synchronization has encountered an error.'));
            foreach ($sync_steps as $sync_step) {
                $batch_builder->addOperation([
                    ConfigImporterBatch::class,
                    'process',
                ], [
                    $config_importer,
                    $sync_step,
                ]);
            }
            batch_set($batch_builder->toArray());
        } catch (ConfigImporterException) {
            // There are validation errors.
            $this->messenger()
                ->addError($this->t('The configuration cannot be imported because it failed validation for the following reasons:'));
            foreach ($config_importer->getErrors() as $message) {
                $this->messenger()
                    ->addError($message);
            }
        }
    }
}

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