function TableDragExampleResetForm::submitForm

Same name in other branches
  1. 3.x modules/tabledrag_example/src/Form/TableDragExampleResetForm.php \Drupal\tabledrag_example\Form\TableDragExampleResetForm::submitForm()

Overrides FormInterface::submitForm

File

modules/tabledrag_example/src/Form/TableDragExampleResetForm.php, line 88

Class

TableDragExampleResetForm
Table drag example reset form.

Namespace

Drupal\tabledrag_example\Form

Code

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');
}