e122f4054346bb6f102aeec95d46baed30c7fc77
[yaffs-website] / web / core / modules / workflows / src / Form / WorkflowDeleteForm.php
1 <?php
2
3 namespace Drupal\workflows\Form;
4
5 use Drupal\Core\Entity\EntityConfirmFormBase;
6 use Drupal\Core\Form\FormStateInterface;
7 use Drupal\Core\Url;
8
9 /**
10  * Builds the form to delete Workflow entities.
11  */
12 class WorkflowDeleteForm extends EntityConfirmFormBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   public function buildForm(array $form, FormStateInterface $form_state) {
18     if ($this->entity->getTypePlugin()->workflowHasData($this->entity)) {
19       $form['#title'] = $this->getQuestion();
20       $form['description'] = ['#markup' => $this->t('This workflow is in use. You cannot remove this workflow until you have removed all content using it.')];
21       return $form;
22     }
23
24     return parent::buildForm($form, $form_state);
25   }
26
27   /**
28    * {@inheritdoc}
29    */
30   public function getQuestion() {
31     return $this->t('Are you sure you want to delete %name?', ['%name' => $this->entity->label()]);
32   }
33
34   /**
35    * {@inheritdoc}
36    */
37   public function getCancelUrl() {
38     return new Url('entity.workflow.collection');
39   }
40
41   /**
42    * {@inheritdoc}
43    */
44   public function getConfirmText() {
45     return $this->t('Delete');
46   }
47
48   /**
49    * {@inheritdoc}
50    */
51   public function submitForm(array &$form, FormStateInterface $form_state) {
52     $this->entity->delete();
53
54     drupal_set_message($this->t(
55       'Workflow %label deleted.',
56       ['%label' => $this->entity->label()]
57     ));
58
59     $form_state->setRedirectUrl($this->getCancelUrl());
60   }
61
62 }