You are here

public function ExportForm::submitForm in Default Content Deploy 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.

Throws

\Exception

Overrides FormInterface::submitForm

File

src/Form/ExportForm.php, line 255

Class

ExportForm
Config Form for run DCD deploy in Admin UI.

Namespace

Drupal\default_content_deploy\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $mode = $form_state
    ->getValue('mode');
  $folder = $form_state
    ->getValue('folder');
  $force_update = $form_state
    ->getValue('force_update');

  // Set mode of export.
  $this->exporter
    ->setMode($mode);

  // Set Entity type id.
  if ($entity_type = $form_state
    ->getValue('entity_type')) {
    $this->exporter
      ->setEntityTypeId($entity_type);
  }

  // Set Bundle of entity type.
  if ($bundle = $form_state
    ->getValue('bundle')) {
    $this->exporter
      ->setEntityBundle($bundle);
  }

  // Set Entity IDs for export.
  if ($entity_ids = $form_state
    ->getValue('entity_ids')) {
    $entity_ids_array = explode(',', $entity_ids);
    $this->exporter
      ->setEntityIds($entity_ids_array);
  }

  // Set Entity IDs to skip.
  if ($skip_ids = $form_state
    ->getValue('skip_entities')) {
    $skip_ids_array = explode(',', $skip_ids);
    $this->exporter
      ->setSkipEntityIds($skip_ids_array);
  }
  if ($form_state
    ->getValue('download') == FALSE) {
    $this->exporter
      ->setForceUpdate($force_update);
    $this->exporter
      ->setFolder($folder);
    $this->exporter
      ->export();
    $this
      ->addResultMessage();
  }
  else {
    $this->exporter
      ->setForceUpdate(TRUE);
    $this->exporter
      ->setFolder($this->fileSystem
      ->getTempDirectory() . '/dcd/content');
    $this->exporter
      ->export();

    // Redirect for download archive file.
    $form_state
      ->setRedirect('default_content_deploy.export.download');
  }
}