You are here

public function TableDragExampleSimpleForm::submitForm in Examples for Developers 8

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

Form submission handler for the simple form.

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/TableDragExampleSimpleForm.php, line 165

Class

TableDragExampleSimpleForm
Table drag example simple form.

Namespace

Drupal\tabledrag_example\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  // Because the form elements were keyed with the item ids from the database,
  // we can simply iterate through the submitted values.
  $submission = $form_state
    ->getValue('table-row');
  foreach ($submission as $id => $item) {
    $this->database
      ->update('tabledrag_example')
      ->fields([
      'weight' => $item['weight'],
      'description' => $item['description'],
    ])
      ->condition('id', $id, '=')
      ->execute();
  }
}