KeyDeleteForm.php in Key 8
File
src/Form/KeyDeleteForm.php
View source
<?php
namespace Drupal\key\Form;
use Drupal\Core\Entity\EntityDeleteForm;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\key\Plugin\KeyPluginDeleteFormInterface;
class KeyDeleteForm extends EntityDeleteForm {
public function getQuestion() {
return $this
->t('Are you sure you want to delete the key %key?', [
'%key' => $this->entity
->label(),
]);
}
public function getCancelUrl() {
return new Url('entity.key.collection');
}
public function getConfirmText() {
return $this
->t('Delete');
}
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
foreach ($this->entity
->getPlugins() as $plugin) {
if ($plugin instanceof KeyPluginDeleteFormInterface) {
$plugin
->buildDeleteForm($form, $form_state);
}
}
return $form;
}
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
foreach ($this->entity
->getPlugins() as $plugin) {
if ($plugin instanceof KeyPluginDeleteFormInterface) {
$plugin
->validateDeleteForm($form, $form_state);
}
}
}
public function getDeletionMessage() {
return $this
->t('The key %label has been deleted.', [
'%label' => $this->entity
->label(),
]);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
foreach ($this->entity
->getPlugins() as $plugin) {
if ($plugin instanceof KeyPluginDeleteFormInterface) {
$plugin
->submitDeleteForm($form, $form_state);
}
}
}
}