function ConfigImportForm::submitForm

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

Overrides FormInterface::submitForm

File

core/modules/config/src/Form/ConfigImportForm.php, line 125

Class

ConfigImportForm
Defines the configuration import form.

Namespace

Drupal\config\Form

Code

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

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