RegistrantDeleteForm.php in RNG - Events and Registrations 3.x
File
src/Form/Entity/RegistrantDeleteForm.php
View source
<?php
namespace Drupal\rng\Form\Entity;
use Drupal\Core\Entity\ContentEntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
class RegistrantDeleteForm extends ContentEntityConfirmFormBase {
public function getQuestion() {
return $this
->t('Are you sure you want to delete this registrant?');
}
public function getCancelUrl() {
return $this->entity
->toUrl();
}
public function getConfirmText() {
return t('Delete');
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$registrant = $this->entity;
$registrant
->delete();
$this
->messenger()
->addMessage($this
->t('Registrant deleted.'));
$registration = $registrant
->getRegistration();
if ($url = $registration
->toUrl()) {
$form_state
->setRedirectUrl($url);
}
else {
$form_state
->setRedirect('<front>');
}
}
}