public function TaxRateForm::save in Ubercart 8.4
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
- uc_tax/
src/ Form/ TaxRateForm.php, line 167
Class
- TaxRateForm
- Builds the form to edit tax rate entities.
Namespace
Drupal\uc_tax\FormCode
public function save(array $form, FormStateInterface $form_state) {
// Save machine names of product types and line item types.
$this->entity
->setProductTypes(array_filter($form_state
->getValue('product_types')));
$this->entity
->setLineItemTypes(array_filter($form_state
->getValue('line_item_types')));
$status = $this->entity
->save();
// Create an edit link for the logger message.
$edit_link = Link::fromTextAndUrl($this
->t('Edit'), $this->entity
->toUrl())
->toString();
if ($status == SAVED_UPDATED) {
// If we edited an existing entity.
$this
->messenger()
->addMessage($this
->t('Tax rate %label has been updated.', [
'%label' => $this->entity
->label(),
]));
$this
->logger('uc_tax')
->notice('Tax rate %label has been updated.', [
'%label' => $this->entity
->label(),
'link' => $edit_link,
]);
}
else {
// If we created a new entity.
$this
->messenger()
->addMessage($this
->t('Tax rate %label has been added.', [
'%label' => $this->entity
->label(),
]));
$this
->logger('uc_tax')
->notice('Tax rate %label has been added.', [
'%label' => $this->entity
->label(),
'link' => $edit_link,
]);
}
$form_state
->setRedirectUrl($this->entity
->toUrl('collection'));
}