4cf56c32832996f341e841cab2d784c2b57669e9
[yaffs-website] / src / Form / DeleteForm.php
1 <?php
2
3 namespace Drupal\forum\Form;
4
5 use Drupal\Core\Form\ConfirmFormBase;
6 use Drupal\Core\Form\FormStateInterface;
7 use Drupal\Core\Url;
8 use Drupal\taxonomy\TermInterface;
9
10 /**
11  * Builds the form to delete a forum term.
12  *
13  * @internal
14  */
15 class DeleteForm extends ConfirmFormBase {
16
17   /**
18    * The taxonomy term being deleted.
19    *
20    * @var \Drupal\taxonomy\TermInterface
21    */
22   protected $taxonomyTerm;
23
24   /**
25    * {@inheritdoc}
26    */
27   public function getFormId() {
28     return 'forum_confirm_delete';
29   }
30
31   /**
32    * {@inheritdoc}
33    */
34   public function getQuestion() {
35     return $this->t('Are you sure you want to delete the forum %label?', ['%label' => $this->taxonomyTerm->label()]);
36   }
37
38   /**
39    * {@inheritdoc}
40    */
41   public function getCancelUrl() {
42     return new Url('forum.overview');
43   }
44
45   /**
46    * {@inheritdoc}
47    */
48   public function getConfirmText() {
49     return $this->t('Delete');
50   }
51
52   /**
53    * {@inheritdoc}
54    */
55   public function buildForm(array $form, FormStateInterface $form_state, TermInterface $taxonomy_term = NULL) {
56     $this->taxonomyTerm = $taxonomy_term;
57
58     return parent::buildForm($form, $form_state);
59   }
60
61   /**
62    * {@inheritdoc}
63    */
64   public function submitForm(array &$form, FormStateInterface $form_state) {
65     $this->taxonomyTerm->delete();
66     $this->messenger()->addStatus($this->t('The forum %label and all sub-forums have been deleted.', ['%label' => $this->taxonomyTerm->label()]));
67     $this->logger('forum')->notice('forum: deleted %label and all its sub-forums.', ['%label' => $this->taxonomyTerm->label()]);
68     $form_state->setRedirectUrl($this->getCancelUrl());
69   }
70
71 }