Commit e9236478 authored by bojanz's avatar bojanz

Stop swalling exceptions in entity forms.

- No exceptions are expected, Drupal should fail fast on all unexpected errors.
- Core doesn't do it either.
parent a71d71cd
......@@ -13,21 +13,6 @@ use Drupal\Core\Form\FormStateInterface;
*/
class OrderForm extends ContentEntityForm {
/**
* Overrides Drupal\Core\Entity\EntityFormController::save().
*/
public function save(array $form, FormStateInterface $form_state) {
try {
$this->entity->save();
drupal_set_message($this->t('The order %order_label has been successfully saved.', ['%order_label' => $this->entity->label()]));
}
catch (\Exception $e) {
drupal_set_message($this->t('The order %order_label could not be saved.', ['%order_label' => $this->entity->label()]), 'error');
$this->logger('commerce_order')->error($e);
}
$form_state->setRedirect('entity.commerce_order.collection');
}
/**
* {@inheritdoc}
*/
......@@ -91,4 +76,13 @@ class OrderForm extends ContentEntityForm {
return $form;
}
/**
* Overrides Drupal\Core\Entity\EntityFormController::save().
*/
public function save(array $form, FormStateInterface $form_state) {
$this->entity->save();
drupal_set_message($this->t('The order %label has been successfully saved.', ['%label' => $this->entity->label()]));
$form_state->setRedirect('entity.commerce_order.collection');
}
}
......@@ -80,21 +80,11 @@ class OrderTypeForm extends EntityForm {
*/
public function save(array $form, FormStateInterface $form_state) {
$orderType = $this->entity;
try {
$orderType->save();
drupal_set_message($this->t('Saved the %label order type.', [
'%label' => $orderType->label(),
]));
$form_state->setRedirect('entity.commerce_order_type.collection');
}
catch (\Exception $e) {
$this->logger('commerce_order')->error($e);
drupal_set_message($this->t('The %label order type was not saved.', [
'%label' => $orderType->label(),
]), 'error');
$form_state->setRebuild();
}
$orderType->save();
drupal_set_message($this->t('Saved the %label order type.', [
'%label' => $orderType->label(),
]));
$form_state->setRedirect('entity.commerce_order_type.collection');
}
}
......@@ -14,21 +14,6 @@ use Drupal\Core\Form\FormStateInterface;
*/
class PaymentInfoForm extends ContentEntityForm {
/**
* Overrides Drupal\Core\Entity\EntityFormController::save().
*/
public function save(array $form, FormStateInterface $form_state) {
try {
$this->entity->save();
drupal_set_message($this->t('The payment information %payment_info_label has been successfully saved.', array('%payment_info_label' => $this->entity->label())));
}
catch (\Exception $e) {
drupal_set_message($this->t('The payment information %payment_info_label could not be saved.', array('%payment_info_label' => $this->entity->label())), 'error');
watchdog_exception('commerce_payment', $e);
}
$form_state->setRedirect('entity.commerce_payment_info.collection');
}
/**
* {@inheritdoc}
*/
......@@ -85,4 +70,13 @@ class PaymentInfoForm extends ContentEntityForm {
return $form;
}
/**
* Overrides Drupal\Core\Entity\EntityFormController::save().
*/
public function save(array $form, FormStateInterface $form_state) {
$this->entity->save();
drupal_set_message($this->t('The payment information %payment_info_label has been successfully saved.', array('%payment_info_label' => $this->entity->label())));
$form_state->setRedirect('entity.commerce_payment_info.collection');
}
}
......@@ -82,21 +82,11 @@ class PaymentInfoTypeForm extends EntityForm {
*/
public function save(array $form, FormStateInterface $form_state) {
$paymentInformationType = $this->entity;
try {
$paymentInformationType->save();
drupal_set_message($this->t('Saved the %payment_info_type_label payment information type.', array(
'%payment_info_type_label' => $paymentInformationType->label(),
)));
$form_state->setRedirect('entity.commerce_payment_info_type.collection');
}
catch (\Exception $e) {
watchdog_exception('commerce_payment', $e);
drupal_set_message($this->t('The %payment_info_type_label payment information type was not saved.', array(
'%payment_info_type_label' => $paymentInformationType->label(),
)), 'error');
$form_state->setRebuild();
}
$paymentInformationType->save();
drupal_set_message($this->t('Saved the %payment_info_type_label payment information type.', array(
'%payment_info_type_label' => $paymentInformationType->label(),
)));
$form_state->setRedirect('entity.commerce_payment_info_type.collection');
}
}
......@@ -143,19 +143,11 @@ class CurrencyForm extends EntityForm {
*/
public function save(array $form, FormStateInterface $form_state) {
$currency = $this->entity;
try {
$currency->save();
drupal_set_message($this->t('Saved the %label currency.', [
'%label' => $currency->label(),
]));
$form_state->setRedirect('entity.commerce_currency.collection');
}
catch (\Exception $e) {
drupal_set_message($this->t('The %label currency was not saved.', ['%label' => $currency->label()]), 'error');
$this->logger('commerce_price')->error($e);
$form_state->setRebuild();
}
$currency->save();
drupal_set_message($this->t('Saved the %label currency.', [
'%label' => $currency->label(),
]));
$form_state->setRedirect('entity.commerce_currency.collection');
}
}
......@@ -62,16 +62,9 @@ class ProductForm extends ContentEntityForm {
public function save(array $form, FormStateInterface $form_state) {
/** @var \Drupal\commerce_product\entity\Product $product */
$product = $this->getEntity();
try {
$product->save();
drupal_set_message($this->t('The product %product_label has been successfully saved.', ['%product_label' => $product->label()]));
$form_state->setRedirect('entity.commerce_product.canonical', ['commerce_product' => $product->id()]);
}
catch (\Exception $e) {
drupal_set_message($this->t('The product %product_label could not be saved.', ['%product_label' => $product->label()]), 'error');
$this->logger('commerce_product')->error($e);
$form_state->setRebuild();
}
$product->save();
drupal_set_message($this->t('The product %label has been successfully saved.', ['%label' => $product->label()]));
$form_state->setRedirect('entity.commerce_product.canonical', ['commerce_product' => $product->id()]);
}
}
......@@ -54,19 +54,12 @@ class ProductTypeForm extends EntityForm {
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
try {
$status = $this->entity->save();
drupal_set_message($this->t('The product type %product_type_label has been successfully saved.', ['%product_type_label' => $this->entity->label()]));
$form_state->setRedirect('entity.commerce_product_type.collection');
$status = $this->entity->save();
drupal_set_message($this->t('The product type %label has been successfully saved.', ['%label' => $this->entity->label()]));
$form_state->setRedirect('entity.commerce_product_type.collection');
if ($status == SAVED_NEW) {
commerce_product_add_body_field($this->id);
}
}
catch (\Exception $e) {
drupal_set_message($this->t('The product type %product_type_label could not be saved.', ['%product_type_label' => $this->entity->label()]), 'error');
$this->logger('commerce_product')->error($e);
$form_state->setRebuild();
if ($status == SAVED_NEW) {
commerce_product_add_body_field($this->id);
}
}
......
......@@ -63,19 +63,13 @@ class StoreForm extends ContentEntityForm {
* Overrides Drupal\Core\Entity\EntityFormController::save().
*/
public function save(array $form, FormStateInterface $form_state) {
try {
$this->entity->save();
if ($form_state->getValue('default')) {
$this->storage->markAsDefault($this->entity);
}
drupal_set_message($this->t('Saved the %label store.', [
'%label' => $this->entity->label(),
]));
}
catch (\Exception $e) {
drupal_set_message($this->t('The store could not be saved.'), 'error');
$this->logger('commerce')->error($e);
$this->entity->save();
if ($form_state->getValue('default')) {
$this->storage->markAsDefault($this->entity);
}
drupal_set_message($this->t('Saved the %label store.', [
'%label' => $this->entity->label(),
]));
$form_state->setRedirect('entity.commerce_store.collection');
}
......
......@@ -48,16 +48,10 @@ class StoreTypeForm extends EntityForm {
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
try {
$this->entity->save();
drupal_set_message($this->t('Saved the %label store type.', [
'%label' => $this->entity->label(),
]));
}
catch (\Exception $e) {
drupal_set_message($this->t('The store type could not be saved.'), 'error');
$this->logger('commerce')->error($e);
}
$this->entity->save();
drupal_set_message($this->t('Saved the %label store type.', [
'%label' => $this->entity->label(),
]));
$form_state->setRedirect('entity.commerce_store_type.collection');
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment