public function TableDragExampleResetForm::submitForm in Examples for Developers 8
Same name and namespace in other branches
- 3.x modules/tabledrag_example/src/Form/TableDragExampleResetForm.php \Drupal\tabledrag_example\Form\TableDragExampleResetForm::submitForm()
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
- tabledrag_example/
src/ Form/ TableDragExampleResetForm.php, line 88
Class
- TableDragExampleResetForm
- Table drag example reset form.
Namespace
Drupal\tabledrag_example\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$data = Fixtures::getSampleItems();
foreach ($data as $id => $item) {
// Add 1 to each array key to match ID.
$id++;
$this->database
->update('tabledrag_example')
->fields([
'weight' => 0,
'pid' => 0,
'description' => $item['description'],
'itemgroup' => $item['itemgroup'],
])
->condition('id', $id, '=')
->execute();
}
$this
->messenger()
->addMessage($this
->t('Data for TableDrag Example has been reset.'), 'status');
$form_state
->setRedirect('tabledrag_example.description');
}