EckEntityTypeDeleteForm.php in Entity Construction Kit (ECK) 8
File
src/Form/EntityType/EckEntityTypeDeleteForm.php
View source
<?php
namespace Drupal\eck\Form\EntityType;
use Drupal\Core\Entity\EntityDeleteForm;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
class EckEntityTypeDeleteForm extends EntityDeleteForm {
public function getQuestion() {
return $this
->t('Are you sure you want to delete entity type %label?', [
'%label' => $this->entity
->label(),
]);
}
public function getConfirmText() {
return $this
->t('Delete entity type');
}
public function getCancelUrl() {
return new Url('eck.entity_type.list');
}
public function buildForm(array $form, FormStateInterface $form_state) {
$content_number = $this->entityTypeManager
->getStorage($this->entity
->id())
->getQuery()
->accessCheck(FALSE)
->count()
->execute();
if (!empty($content_number)) {
$warning_message = '<p>' . $this
->formatPlural($content_number, 'There is 1 %type entity. You can not remove this entity type until you have removed all of the %type entities.', 'There are @count %type entities. You may not remove %type until you have removed all of the %type entities.', [
'%type' => $this->entity
->label(),
]) . '</p>';
$form['#title'] = $this
->getConfirmText();
$form['description'] = [
'#markup' => $warning_message,
];
return $form;
}
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$form_state
->setRedirectUrl(new Url('eck.entity_type.list'));
}
}