ConfigImportForm::submitForm

public ConfigImportForm::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/ConfigImportForm.php, line 91

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 = array();
      foreach ($archiver->listContent() as $file) {
        $files[] = $file['filename'];
      }
      $archiver->extractList($files, config_get_config_directory(CONFIG_SYNC_DIRECTORY));
      drupal_set_message($this->t('Your configuration files were successfully uploaded and are ready for import.'));
      $form_state->setRedirect('config.sync');
    }
    catch (\Exception $e) {
      drupal_set_message($this->t('Could not extract the contents of the tar file. The error message is <em>@message</em>', array('@message' => $e->getMessage())), 'error');
    }
    drupal_unlink($path);
  }
}
doc_Drupal
2016-10-29 08:53:47
Comments
Leave a Comment

Please login to continue.