public function ProductForm::save in Commerce Core 8.2
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
- modules/
product/ src/ Form/ ProductForm.php, line 234
Class
- ProductForm
- Defines the product add/edit form.
Namespace
Drupal\commerce_product\FormCode
public function save(array $form, FormStateInterface $form_state) {
/** @var \Drupal\commerce_product\Entity\ProductInterface $product */
$product = $this
->getEntity();
$product
->save();
$this
->messenger()
->addMessage($this
->t('The product %label has been successfully saved.', [
'%label' => $product
->label(),
]));
if (!empty($form_state
->getTriggeringElement()['#continue'])) {
$form_state
->setRedirect('entity.commerce_product_variation.collection', [
'commerce_product' => $product
->id(),
]);
}
else {
$form_state
->setRedirect('entity.commerce_product.canonical', [
'commerce_product' => $product
->id(),
]);
}
}