3 namespace Drupal\workflows\Form;
5 use Drupal\workflows\WorkflowInterface;
6 use Drupal\Core\Form\ConfirmFormBase;
7 use Drupal\Core\Form\FormStateInterface;
8 use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
11 * Builds the form to delete transitions from Workflow entities.
15 class WorkflowTransitionDeleteForm extends ConfirmFormBase {
18 * The workflow entity the transition being deleted belongs to.
20 * @var \Drupal\workflows\WorkflowInterface
25 * The workflow transition being deleted.
27 * @var \Drupal\workflows\TransitionInterface
29 protected $transition;
32 * The transition being deleted.
36 protected $transitionId;
41 public function getFormId() {
42 return 'workflow_transition_delete_form';
48 public function getQuestion() {
49 return $this->t('Are you sure you want to delete %transition from %workflow?', ['%transition' => $this->transition->label(), '%workflow' => $this->workflow->label()]);
55 public function getCancelUrl() {
56 return $this->workflow->toUrl();
62 public function getConfirmText() {
63 return $this->t('Delete');
70 * An associative array containing the structure of the form.
71 * @param \Drupal\Core\Form\FormStateInterface $form_state
72 * The current state of the form.
73 * @param \Drupal\workflows\WorkflowInterface $workflow
74 * The workflow entity being edited.
75 * @param string|null $workflow_transition
76 * The workflow transition being deleted.
81 public function buildForm(array $form, FormStateInterface $form_state, WorkflowInterface $workflow = NULL, $workflow_transition = NULL) {
83 $this->transition = $workflow->getTypePlugin()->getTransition($workflow_transition);
85 catch (\InvalidArgumentException $e) {
86 throw new NotFoundHttpException();
88 $this->workflow = $workflow;
89 return parent::buildForm($form, $form_state);
95 public function submitForm(array &$form, FormStateInterface $form_state) {
98 ->deleteTransition($this->transition->id());
99 $this->workflow->save();
101 $this->messenger()->addStatus($this->t('%transition transition deleted.', ['%transition' => $this->transition->label()]));
102 $form_state->setRedirectUrl($this->getCancelUrl());