3 namespace Drupal\forum\Form;
5 use Drupal\Core\Form\ConfirmFormBase;
6 use Drupal\Core\Form\FormStateInterface;
8 use Drupal\taxonomy\TermInterface;
11 * Builds the form to delete a forum term.
15 class DeleteForm extends ConfirmFormBase {
18 * The taxonomy term being deleted.
20 * @var \Drupal\taxonomy\TermInterface
22 protected $taxonomyTerm;
27 public function getFormId() {
28 return 'forum_confirm_delete';
34 public function getQuestion() {
35 return $this->t('Are you sure you want to delete the forum %label?', ['%label' => $this->taxonomyTerm->label()]);
41 public function getCancelUrl() {
42 return new Url('forum.overview');
48 public function getConfirmText() {
49 return $this->t('Delete');
55 public function buildForm(array $form, FormStateInterface $form_state, TermInterface $taxonomy_term = NULL) {
56 $this->taxonomyTerm = $taxonomy_term;
58 return parent::buildForm($form, $form_state);
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());