You are here

public function DbtngExampleUpdateForm::submitForm in Examples for Developers 3.x

Same name and namespace in other branches
  1. 8 dbtng_example/src/Form/DbtngExampleUpdateForm.php \Drupal\dbtng_example\Form\DbtngExampleUpdateForm::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

modules/dbtng_example/src/Form/DbtngExampleUpdateForm.php, line 163

Class

DbtngExampleUpdateForm
Sample UI to update a record.

Namespace

Drupal\dbtng_example\Form

Code

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

  // Gather the current user so the new record has ownership.
  $account = $this
    ->currentUser();

  // Save the submitted entry.
  $entry = [
    'pid' => $form_state
      ->getValue('pid'),
    'name' => $form_state
      ->getValue('name'),
    'surname' => $form_state
      ->getValue('surname'),
    'age' => $form_state
      ->getValue('age'),
    'uid' => $account
      ->id(),
  ];
  $count = $this->repository
    ->update($entry);
  $this
    ->messenger()
    ->addMessage($this
    ->t('Updated entry @entry (@count row updated)', [
    '@count' => $count,
    '@entry' => print_r($entry, TRUE),
  ]));
}