public function ScannerForm::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/ ScannerForm.php, line 189
Class
- ScannerForm
- Form for performing searching.
Namespace
Drupal\scanner\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_state
->cleanValues();
$scannerStore = $this->tempStore
->get('scanner');
$op = $form_state
->getUserInput()['op'];
// Save the $form_state values into the user tempstore for later.
foreach ($form_state
->getValues() as $key => $value) {
$scannerStore
->set($key, $form_state
->getValue($key));
}
$scannerStore
->set('op', $op);
if ($op == $this
->t('Search')) {
$fields = \Drupal::config('scanner.admin_settings')
->get('fields_of_selected_content_type');
// Build an array of batch operation jobs.
// Batch job will need the field and the $form_state values.
$operations = [];
foreach ($fields as $key => $field) {
$operations[] = [
'\\Drupal\\scanner\\Form\\ScannerForm::batchSearch',
[
$field,
$form_state
->getValues(),
],
];
}
$batch = [
'title' => $this
->t('Scanner Search Batch'),
'operations' => $operations,
'finished' => '\\Drupal\\scanner\\Form\\ScannerForm::batchFinished',
'progress_message' => $this
->t('Processed @current out of @total'),
];
batch_set($batch);
$form_state
->setRebuild(TRUE);
}
elseif ($op == $this
->t('Replace')) {
// Redirect to the confirmation form.
$form_state
->setRedirect('scanner.admin_confirm');
}
}