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.
13 class WorkflowTransitionDeleteForm extends ConfirmFormBase {
16 * The workflow entity the transition being deleted belongs to.
18 * @var \Drupal\workflows\WorkflowInterface
23 * The workflow transition being deleted.
25 * @var \Drupal\workflows\TransitionInterface
27 protected $transition;
30 * The transition being deleted.
34 protected $transitionId;
39 public function getFormId() {
40 return 'workflow_transition_delete_form';
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()]);
53 public function getCancelUrl() {
54 return $this->workflow->toUrl();
60 public function getConfirmText() {
61 return $this->t('Delete');
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.
79 public function buildForm(array $form, FormStateInterface $form_state, WorkflowInterface $workflow = NULL, $workflow_transition = NULL) {
81 $this->transition = $workflow->getTypePlugin()->getTransition($workflow_transition);
83 catch (\InvalidArgumentException $e) {
84 throw new NotFoundHttpException();
86 $this->workflow = $workflow;
87 return parent::buildForm($form, $form_state);
93 public function submitForm(array &$form, FormStateInterface $form_state) {
96 ->deleteTransition($this->transition->id());
97 $this->workflow->save();
99 drupal_set_message($this->t('%transition transition deleted.', ['%transition' => $this->transition->label()]));
100 $form_state->setRedirectUrl($this->getCancelUrl());