public function TransactionOperationForm::save in Transaction 8
Form submission handler for the 'save' action.
Normally this method should be overridden to provide specific messages to the user and redirect the form after the entity has been saved.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
int Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed.
Overrides EntityForm::save
File
- src/
Form/ TransactionOperationForm.php, line 136
Class
- TransactionOperationForm
- Builds the form to add or edit a transaction operation.
Namespace
Drupal\transaction\FormCode
public function save(array $form, FormStateInterface $form_state) {
/** @var \Drupal\transaction\TransactionOperationInterface $transaction_operation */
$transaction_operation = $this->entity;
$status = $transaction_operation
->save();
// Messages.
$t_args = [
'%label' => $transaction_operation
->label(),
];
$logger_args = $t_args + [
'link' => $transaction_operation
->toLink($this
->t('Edit'), 'edit-form')
->toString(),
];
if ($status == SAVED_UPDATED) {
$this
->messenger()
->addStatus($this
->t('Transaction operation %label has been updated.', $t_args));
$this
->logger('transaction')
->notice('Transaction operation %label has been updated.', $logger_args);
}
else {
$this
->messenger()
->addStatus($this
->t('Transaction operation %label has been added.', $t_args));
$this
->logger('transaction')
->notice('Transaction operation %label has been added.', $logger_args);
}
$form_state
->setRedirect('entity.transaction_operation.collection', [
'transaction_type' => $transaction_operation
->getTransactionTypeId(),
]);
}