RegistrantTypeDeleteForm.php in RNG - Events and Registrations 8
File
src/Form/Entity/RegistrantTypeDeleteForm.php
View source
<?php
namespace Drupal\rng\Form\Entity;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Entity\EntityDeleteForm;
use Drupal\Core\Url;
class RegistrantTypeDeleteForm extends EntityDeleteForm {
public function getQuestion() {
return $this
->t('Are you sure you want to delete registrant type %label?', array(
'%label' => $this->entity
->label(),
));
}
public function getDescription() {
return t('Deleting this registrant type will also delete the associated registration.');
}
public function getConfirmText() {
return $this
->t('Delete');
}
public function getCancelUrl() {
return new Url('entity.registrant_type.collection');
}
public function buildForm(array $form, FormStateInterface $form_state) {
$registrant_type =& $this->entity;
$count = $this->entityTypeManager
->getStorage('registrant')
->getQuery()
->condition('type', $registrant_type
->id())
->count()
->execute();
if ($count > 0) {
drupal_set_message($this
->t('Cannot delete registrant type.'), 'warning');
$form['#title'] = $this
->getQuestion();
$form['description'] = [
'#markup' => $this
->formatPlural($count, 'Unable to delete registrant type. It is used by @count registration.', 'Unable to delete registrant type. It is used by @count registrations.'),
];
}
else {
$form = parent::buildForm($form, $form_state);
}
return $form;
}
}