You are here

public function DemoConfigResetConfirm::submitForm in Demonstration site (Sandbox / Snapshot) 8

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

src/Form/DemoConfigResetConfirm.php, line 50

Class

DemoConfigResetConfirm
This class return the form demo_config_reset_confirm to make sure that you are about to reset your configuration.

Namespace

Drupal\demo\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  // Reset site to chosen snapshot.
  if ($path = $form_state
    ->getValue('filename')) {
    try {
      $archiver = new ArchiveTar($path, 'gz');
      $files = [];
      foreach ($archiver
        ->listContent() as $file) {
        $files[] = $file['filename'];
      }
      $archiver
        ->extractList($files, config_get_config_directory(CONFIG_SYNC_DIRECTORY));
      \Drupal::messenger()
        ->addMessage($this
        ->t('Your configuration files were successfully uploaded and are ready for import.'));
      $form_state
        ->setRedirect('demo.config_sync');
    } catch (\Exception $e) {
      \Drupal::messenger()
        ->addMessage($this
        ->t('Could not extract the contents of the tar file. The error message is <em>@message</em>', [
        '@message' => $e
          ->getMessage(),
      ]), 'error');
    }
  }
}