PollDeleteForm.php in Poll 8
File
src/Form/PollDeleteForm.php
View source
<?php
namespace Drupal\poll\Form;
use Drupal\Core\Entity\ContentEntityConfirmFormBase;
use Drupal\Core\Url;
use Drupal\Core\Form\FormStateInterface;
class PollDeleteForm extends ContentEntityConfirmFormBase {
public function getDescription() {
return t('All associated votes will be deleted too. This action cannot be undone.');
}
public function getQuestion() {
return $this
->t('Are you sure you want to delete this poll %poll', array(
'%poll' => $this->entity
->label(),
));
}
public function getCancelUrl() {
return new Url('poll.poll_list');
}
public function getConfirmText() {
return $this
->t('Delete');
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->entity
->delete();
\Drupal::logger('poll')
->notice('Poll %poll deleted.', array(
'%poll' => $this->entity
->label(),
));
$this
->messenger()
->addMessage($this
->t('The poll %poll has been deleted.', array(
'%poll' => $this->entity
->label(),
)));
$form_state
->setRedirect('poll.poll_list');
}
}