You are here

public function RedirectImportForm::submitForm in Path redirect import 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/RedirectImportForm.php, line 134

Class

RedirectImportForm
Class RedirectImportForm.

Namespace

Drupal\path_redirect_import\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  ini_set('auto_detect_line_endings', TRUE);

  // Don't do anything if no valid file.
  if (!isset($this->file)) {
    $this
      ->messenger()
      ->addWarning($this
      ->t('No valid file was found. No redirects have been imported.'));
    return;
  }
  $options = [
    'status_code' => $form_state
      ->getValue('status_code'),
    'override' => $form_state
      ->getValue('override'),
    'no_headers' => $form_state
      ->getValue('no_headers'),
    'delimiter' => $form_state
      ->getValue('delimiter'),
    'language' => $form_state
      ->getValue('language') ?: Language::LANGCODE_NOT_SPECIFIED,
    'suppress_messages' => $form_state
      ->getValue('suppress_messages'),
    'allow_nonexistent' => $form_state
      ->getValue('allow_nonexistent'),
  ];
  ImporterService::import($this->file, $options);

  // Remove file from Drupal managed files & from filesystem.
  \Drupal::service('entity_type.manager')
    ->getStorage('file')
    ->delete([
    $this->file,
  ]);
}