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