PromotionDisableForm.php in Commerce Core 8.2
File
modules/promotion/src/Form/PromotionDisableForm.php
View source
<?php
namespace Drupal\commerce_promotion\Form;
use Drupal\Core\Entity\ContentEntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
class PromotionDisableForm extends ContentEntityConfirmFormBase {
public function getQuestion() {
return $this
->t('Are you sure you want to disable the promotion %label?', [
'%label' => $this
->getEntity()
->label(),
]);
}
public function getConfirmText() {
return $this
->t('Disable');
}
public function getCancelUrl() {
return Url::fromRoute('entity.commerce_promotion.collection');
}
public function getDescription() {
return '';
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$promotion = $this
->getEntity();
$promotion
->setEnabled(FALSE);
$promotion
->save();
$this
->messenger()
->addStatus($this
->t('Successfully disabled the promotion %label', [
'%label' => $promotion
->label(),
]));
$form_state
->setRedirectUrl($this
->getCancelUrl());
}
}