You are here

public function LibraryAlterTransactionForm::submitForm in Library 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/LibraryAlterTransactionForm.php, line 121

Class

LibraryAlterTransactionForm
Alter the library transaction form.

Namespace

Drupal\library\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $transaction = LibraryTransaction::load($form_state
    ->getValue('transaction'));
  $transaction
    ->set('notes', $form_state
    ->getValue('notes'));
  $transaction
    ->save();

  // @todo Inject.
  \Drupal::service('cache_tags.invalidator')
    ->invalidateTags([
    'node:' . $form_state
      ->getValue('nid'),
  ]);
  $this
    ->messenger()
    ->addStatus($this
    ->t('Transaction updated.'));
  \Drupal::service('event_dispatcher')
    ->dispatch('library.action', new ActionEvent($transaction));
  $form_state
    ->setRedirect('entity.node.canonical', [
    'node' => $form_state
      ->getValue('nid'),
  ]);
}