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 states from Workflow entities.
13 class WorkflowStateDeleteForm extends ConfirmFormBase {
16 * The workflow entity the state being deleted belongs to.
18 * @var \Drupal\workflows\WorkflowInterface
23 * The state being deleted.
32 public function getFormId() {
33 return 'workflow_state_delete_form';
39 public function getQuestion() {
40 return $this->t('Are you sure you want to delete %state from %workflow?', ['%state' => $this->workflow->getState($this->stateId)->label(), '%workflow' => $this->workflow->label()]);
46 public function getCancelUrl() {
47 return $this->workflow->toUrl();
53 public function getConfirmText() {
54 return $this->t('Delete');
61 * An associative array containing the structure of the form.
62 * @param \Drupal\Core\Form\FormStateInterface $form_state
63 * The current state of the form.
64 * @param \Drupal\workflows\WorkflowInterface $workflow
65 * The workflow entity being edited.
66 * @param string|null $workflow_state
67 * The workflow state being deleted.
72 public function buildForm(array $form, FormStateInterface $form_state, WorkflowInterface $workflow = NULL, $workflow_state = NULL) {
73 if (!$workflow->hasState($workflow_state)) {
74 throw new NotFoundHttpException();
76 $this->workflow = $workflow;
77 $this->stateId = $workflow_state;
78 return parent::buildForm($form, $form_state);
84 public function submitForm(array &$form, FormStateInterface $form_state) {
86 $workflow_label = $this->workflow->getState($this->stateId)->label();
88 ->deleteState($this->stateId)
91 drupal_set_message($this->t(
92 'State %label deleted.',
93 ['%label' => $workflow_label]
96 $form_state->setRedirectUrl($this->getCancelUrl());