CouponForm.php in Commerce Core 8.2
File
modules/promotion/src/Form/CouponForm.php
View source
<?php
namespace Drupal\commerce_promotion\Form;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Form\FormStateInterface;
class CouponForm extends ContentEntityForm {
protected function prepareEntity() {
if ($this->entity
->isNew()) {
$promotion = $this
->getRouteMatch()
->getParameter('commerce_promotion');
$this->entity
->set('promotion_id', $promotion);
}
}
public function save(array $form, FormStateInterface $form_state) {
$this->entity
->save();
$this
->messenger()
->addMessage($this
->t('Saved the %label coupon.', [
'%label' => $this->entity
->label(),
]));
$form_state
->setRedirectUrl($this->entity
->toUrl('collection'));
}
}