You are here

public function EditWordForm::submitForm in Restrict Abusive Words 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/EditWordForm.php, line 70
Contains \Drupal\restrict_abusive_words\Form\EditWordForm.

Class

EditWordForm
Contribute form.

Namespace

Drupal\restrict_abusive_words\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $connection = Database::getConnection();
  if (!empty($form_state
    ->getValue('id')) && !empty($form_state
    ->getValue('id'))) {
    $query = $connection
      ->update('restrict_abusive_words');
    $query
      ->condition('id', $form_state
      ->getValue('id'));
    $query
      ->fields(array(
      'words' => $form_state
        ->getValue('words'),
    ));

    // Execute the statement
    $data = $query
      ->execute();
    drupal_set_message(t('Added word: %word', array(
      '%word' => $row->words,
    )));
  }
  $form_state
    ->setRedirect('restrict_abusive_words.list_words');
}