ModalDeleteForm.php in Modal 8.3
File
src/Form/ModalDeleteForm.php
View source
<?php
namespace Drupal\modal_page\Form;
use Drupal\Core\Entity\ContentEntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
class ModalDeleteForm extends ContentEntityConfirmFormBase {
public function getQuestion() {
return $this
->t('Are you sure you want to delete entity %title?', [
'%title' => $this->entity
->label(),
]);
}
public function getCancelUrl() {
return new Url('modal_page.default');
}
public function getConfirmText() {
return $this
->t('Delete');
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$entity = $this
->getEntity();
$entity
->delete();
$this
->logger('modal_page')
->notice('@type: deleted %title.', [
'@type' => $this->entity
->bundle(),
'%title' => $this->entity
->label(),
]);
$this
->messenger()
->addStatus($this
->t('Modal %title deleted.', [
'%title' => $this->entity
->label(),
]));
$form_state
->setRedirect('modal_page.default');
}
}