Newer
Older
Alex Pott
committed
<?php
namespace Drupal\forum\Form;
use Drupal\Core\Form\ConfirmFormBase;
Dries Buytaert
committed
use Drupal\Core\Form\FormStateInterface;
Angie Byron
committed
use Drupal\Core\Url;
Angie Byron
committed
use Drupal\taxonomy\TermInterface;
Alex Pott
committed
/**
* Builds the form to delete a forum term.
*
* @internal
Alex Pott
committed
*/
class DeleteForm extends ConfirmFormBase {
/**
* The taxonomy term being deleted.
*
Angie Byron
committed
* @var \Drupal\taxonomy\TermInterface
Alex Pott
committed
*/
protected $taxonomyTerm;
/**
* {@inheritdoc}
*/
Alex Pott
committed
public function getFormId() {
Alex Pott
committed
return 'forum_confirm_delete';
}
/**
* {@inheritdoc}
*/
public function getQuestion() {
return $this->t('Are you sure you want to delete the forum %label?', ['%label' => $this->taxonomyTerm->label()]);
Alex Pott
committed
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
Angie Byron
committed
return new Url('forum.overview');
Alex Pott
committed
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
Angie Byron
committed
return $this->t('Delete');
Alex Pott
committed
}
/**
* {@inheritdoc}
*/
Dries Buytaert
committed
public function buildForm(array $form, FormStateInterface $form_state, TermInterface $taxonomy_term = NULL) {
Alex Pott
committed
$this->taxonomyTerm = $taxonomy_term;
return parent::buildForm($form, $form_state);
Alex Pott
committed
}
/**
* {@inheritdoc}
*/
Dries Buytaert
committed
public function submitForm(array &$form, FormStateInterface $form_state) {
Alex Pott
committed
$this->taxonomyTerm->delete();
$this->messenger()->addStatus($this->t('The forum %label and all sub-forums have been deleted.', ['%label' => $this->taxonomyTerm->label()]));
$this->logger('forum')->notice('forum: deleted %label and all its sub-forums.', ['%label' => $this->taxonomyTerm->label()]);
Alex Pott
committed
$form_state->setRedirectUrl($this->getCancelUrl());