public function ConfigImportForm::submitForm in Drupal 9
Same name and namespace in other branches
- 8 core/modules/config/src/Form/ConfigImportForm.php \Drupal\config\Form\ConfigImportForm::submitForm()
- 10 core/modules/config/src/Form/ConfigImportForm.php \Drupal\config\Form\ConfigImportForm::submitForm()
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/ ConfigImportForm.php, line 117
Class
- ConfigImportForm
- Defines the configuration import form.
Namespace
Drupal\config\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
if ($path = $form_state
->getValue('import_tarball')) {
$this->configStorage
->deleteAll();
try {
$archiver = new ArchiveTar($path, 'gz');
$files = [];
foreach ($archiver
->listContent() as $file) {
$files[] = $file['filename'];
}
$archiver
->extractList($files, $this->settings
->get('config_sync_directory'), '', FALSE, FALSE);
$this
->messenger()
->addStatus($this
->t('Your configuration files were successfully uploaded and are ready for import.'));
$form_state
->setRedirect('config.sync');
} catch (\Exception $e) {
$this
->messenger()
->addError($this
->t('Could not extract the contents of the tar file. The error message is <em>@message</em>', [
'@message' => $e
->getMessage(),
]));
}
$this->fileSystem
->unlink($path);
}
}