You are here

public function ScannerConfirmForm::submitForm in Search and Replace Scanner 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/ScannerConfirmForm.php, line 66

Class

ScannerConfirmForm
Form for configure messages.

Namespace

Drupal\scanner\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $scannerStore = $this->tempStore
    ->get('scanner');
  foreach ([
    'search',
    'replace',
    'mode',
    'wholeword',
    'regex',
    'preceded',
    'followed',
    'published',
    'language',
  ] as $value) {
    $values[$value] = $scannerStore
      ->get($value);
  }
  $fields = \Drupal::config('scanner.admin_settings')
    ->get('fields_of_selected_content_type');
  $operations = [];

  // Build an array of batch operation jobs. Batch job will need the field
  // and the filter values the users entered in the form.
  foreach ($fields as $field) {
    $operations[] = [
      '\\Drupal\\scanner\\Form\\ScannerConfirmForm::batchReplace',
      [
        $field,
        $values,
      ],
    ];
  }
  $batch = [
    'title' => $this
      ->t('Scanner Replace Batch'),
    'operations' => $operations,
    'finished' => '\\Drupal\\scanner\\Form\\ScannerConfirmForm::batchFinished',
    'progress_message' => $this
      ->t('Processed @current out of @total'),
  ];
  batch_set($batch);

  // Redirect to the scanner page after the batch is done.
  $form_state
    ->setRedirect('scanner.admin_content');
}