public function ScannerConfirmUndoForm::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/ ScannerConfirmUndoForm.php, line 40
Class
- ScannerConfirmUndoForm
- Displayed to confirm that the user want to undo the replace operation.
Namespace
Drupal\scanner\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$connection = \Drupal::service('database');
$undo_id = $form_state
->getValue('undo_id', 0);
if (!empty($undo_id) && $undo_id > 0) {
// Query the database in order to find the specific record we're trying
// to undo.
$query = $connection
->query('SELECT undo_data from scanner WHERE undone = :undone and undo_id = :id', [
':undone' => 0,
':id' => $undo_id,
]);
$results = $query
->fetchCol()[0];
$data = unserialize($results);
$operations[] = [
'\\Drupal\\scanner\\Form\\ScannerConfirmUndoForm::batchUndo',
[
$data,
$undo_id,
],
];
$batch = [
'title' => $this
->t('Scanner Replace Batch'),
'operations' => $operations,
'finished' => '\\Drupal\\scanner\\Form\\ScannerConfirmUndoForm::batchFinished',
'progress_message' => $this
->t('Processed @current out of @total'),
];
batch_set($batch);
}
$form_state
->setRedirect('scanner.undo');
}