Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / workflows / src / Form / WorkflowTransitionDeleteForm.php
1 <?php
2
3 namespace Drupal\workflows\Form;
4
5 use Drupal\workflows\WorkflowInterface;
6 use Drupal\Core\Form\ConfirmFormBase;
7 use Drupal\Core\Form\FormStateInterface;
8 use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
9
10 /**
11  * Builds the form to delete transitions from Workflow entities.
12  */
13 class WorkflowTransitionDeleteForm extends ConfirmFormBase {
14
15   /**
16    * The workflow entity the transition being deleted belongs to.
17    *
18    * @var \Drupal\workflows\WorkflowInterface
19    */
20   protected $workflow;
21
22   /**
23    * The workflow transition being deleted.
24    *
25    * @var \Drupal\workflows\TransitionInterface
26    */
27   protected $transition;
28
29   /**
30    * The transition being deleted.
31    *
32    * @var string
33    */
34   protected $transitionId;
35
36   /**
37    * {@inheritdoc}
38    */
39   public function getFormId() {
40     return 'workflow_transition_delete_form';
41   }
42
43   /**
44    * {@inheritdoc}
45    */
46   public function getQuestion() {
47     return $this->t('Are you sure you want to delete %transition from %workflow?', ['%transition' => $this->transition->label(), '%workflow' => $this->workflow->label()]);
48   }
49
50   /**
51    * {@inheritdoc}
52    */
53   public function getCancelUrl() {
54     return $this->workflow->toUrl();
55   }
56
57   /**
58    * {@inheritdoc}
59    */
60   public function getConfirmText() {
61     return $this->t('Delete');
62   }
63
64   /**
65    * Form constructor.
66    *
67    * @param array $form
68    *   An associative array containing the structure of the form.
69    * @param \Drupal\Core\Form\FormStateInterface $form_state
70    *   The current state of the form.
71    * @param \Drupal\workflows\WorkflowInterface $workflow
72    *   The workflow entity being edited.
73    * @param string|null $workflow_transition
74    *   The workflow transition being deleted.
75    *
76    * @return array
77    *   The form structure.
78    */
79   public function buildForm(array $form, FormStateInterface $form_state, WorkflowInterface $workflow = NULL, $workflow_transition = NULL) {
80     try {
81       $this->transition = $workflow->getTypePlugin()->getTransition($workflow_transition);
82     }
83     catch (\InvalidArgumentException $e) {
84       throw new NotFoundHttpException();
85     }
86     $this->workflow = $workflow;
87     return parent::buildForm($form, $form_state);
88   }
89
90   /**
91    * {@inheritdoc}
92    */
93   public function submitForm(array &$form, FormStateInterface $form_state) {
94     $this->workflow
95       ->getTypePlugin()
96       ->deleteTransition($this->transition->id());
97     $this->workflow->save();
98
99     drupal_set_message($this->t('%transition transition deleted.', ['%transition' => $this->transition->label()]));
100     $form_state->setRedirectUrl($this->getCancelUrl());
101   }
102
103 }