DomainDeleteForm.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace Drupal\domain\Form;
  3. use Drupal\Core\Entity\EntityConfirmFormBase;
  4. use Drupal\Core\Form\FormStateInterface;
  5. use Drupal\Core\Url;
  6. /**
  7. * Builds the form to delete a domain record.
  8. */
  9. class DomainDeleteForm extends EntityConfirmFormBase {
  10. /**
  11. * {@inheritdoc}
  12. */
  13. public function getQuestion() {
  14. return $this->t('Are you sure you want to delete %name?', ['%name' => $this->entity->label()]);
  15. }
  16. /**
  17. * {@inheritdoc}
  18. */
  19. public function getCancelUrl() {
  20. return new Url('domain.admin');
  21. }
  22. /**
  23. * {@inheritdoc}
  24. */
  25. public function getConfirmText() {
  26. return $this->t('Delete');
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function submitForm(array &$form, FormStateInterface $form_state) {
  32. $this->entity->delete();
  33. \Drupal::messenger()->addMessage($this->t('Domain %label has been deleted.', ['%label' => $this->entity->label()]));
  34. \Drupal::logger('domain')->notice('Domain %label has been deleted.', ['%label' => $this->entity->label()]);
  35. $form_state->setRedirectUrl($this->getCancelUrl());
  36. }
  37. }