public ConfigSingleImportForm::submitForm(array &$form, FormStateInterface $form_state)
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormInterface::submitForm
File
- core/modules/config/src/Form/ConfigSingleImportForm.php, line 384
Class
- ConfigSingleImportForm
- Provides a form for importing a single configuration file.
Namespace
Drupal\config\Form
Code
public function submitForm(array &$form, FormStateInterface $form_state) {
// If this form has not yet been confirmed, store the values and rebuild.
if (!$this->data) {
$form_state->setRebuild();
$this->data = $form_state->getValues();
return;
}
/** @var \Drupal\Core\Config\ConfigImporter $config_importer */
$config_importer = $form_state->get('config_importer');
if ($config_importer->alreadyImporting()) {
drupal_set_message($this->t('Another request may be importing configuration already.'), 'error');
}
else {
try {
$sync_steps = $config_importer->initialize();
$batch = [
'operations' => [],
'finished' => [ConfigSync::class, 'finishBatch'],
'title' => $this->t('Importing configuration'),
'init_message' => $this->t('Starting configuration import.'),
'progress_message' => $this->t('Completed @current step of @total.'),
'error_message' => $this->t('Configuration import has encountered an error.'),
];
foreach ($sync_steps as $sync_step) {
$batch['operations'][] = [[ConfigSync::class, 'processBatch'], [$config_importer, $sync_step]];
}
batch_set($batch);
}
catch (ConfigImporterException $e) {
// There are validation errors.
drupal_set_message($this->t('The configuration import failed for the following reasons:'), 'error');
foreach ($config_importer->getErrors() as $message) {
drupal_set_message($message, 'error');
}
}
}
}
Please login to continue.