DeleteForm.php in Mail Safety 8
File
src/Form/DeleteForm.php
View source
<?php
namespace Drupal\mail_safety\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\mail_safety\Controller\MailSafetyController;
class DeleteForm extends ConfirmFormBase {
protected $mailSafety = [];
public function getFormId() {
return 'mail_safety_delete_form';
}
public function getQuestion() {
return $this
->t('Are you sure you want to delete this mail?');
}
public function getCancelUrl() {
return new Url('mail_safety.dashboard');
}
public function getConfirmText() {
return $this
->t('Delete mail');
}
public function buildForm(array $form, FormStateInterface $form_state, $mail_safety = NULL) {
$this->mailSafety = $mail_safety;
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
MailSafetyController::delete($this->mailSafety['mail_id']);
$form_state
->setRedirectUrl($this
->getCancelUrl());
}
}