508205738db442f492ca7144c50d5da716c9a8e8
[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  * @internal
13  */
14 class WorkflowDeleteForm extends EntityConfirmFormBase {
15
16   /**
17    * {@inheritdoc}
18    */
19   public function buildForm(array $form, FormStateInterface $form_state) {
20     if ($this->entity->getTypePlugin()->workflowHasData($this->entity)) {
21       $form['#title'] = $this->getQuestion();
22       $form['description'] = ['#markup' => $this->t('This workflow is in use. You cannot remove this workflow until you have removed all content using it.')];
23       return $form;
24     }
25
26     return parent::buildForm($form, $form_state);
27   }
28
29   /**
30    * {@inheritdoc}
31    */
32   public function getQuestion() {
33     return $this->t('Are you sure you want to delete %name?', ['%name' => $this->entity->label()]);
34   }
35
36   /**
37    * {@inheritdoc}
38    */
39   public function getCancelUrl() {
40     return new Url('entity.workflow.collection');
41   }
42
43   /**
44    * {@inheritdoc}
45    */
46   public function getConfirmText() {
47     return $this->t('Delete');
48   }
49
50   /**
51    * {@inheritdoc}
52    */
53   public function submitForm(array &$form, FormStateInterface $form_state) {
54     $this->entity->delete();
55
56     drupal_set_message($this->t(
57       'Workflow %label deleted.',
58       ['%label' => $this->entity->label()]
59     ));
60
61     $form_state->setRedirectUrl($this->getCancelUrl());
62   }
63
64 }