external_entity-1.0.x-dev/src/Form/ExternalEntityDefaultDeleteForm.php
src/Form/ExternalEntityDefaultDeleteForm.php
<?php
declare(strict_types=1);
namespace Drupal\external_entity\Form;
use Drupal\Core\Url;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\StringTranslation\TranslatableMarkup;
/**
* Define the external entity default delete form.
*/
class ExternalEntityDefaultDeleteForm extends EntityConfirmFormBase {
/**
* {@inheritdoc}
*/
public function getQuestion(): TranslatableMarkup {
return $this->t('Are you sure you want to delete %label?', [
'%label' => $this->entity->label(),
]);
}
/**
* {@inheritdoc}
*/
public function getCancelUrl(): Url {
return $this->entity->toUrl('collection');
}
/**
* {@inheritdoc}
*/
public function submitForm(
array &$form,
FormStateInterface $form_state,
): void {
parent::submitForm($form, $form_state);
$this->entity->delete();
$form_state->setRedirectUrl($this->getCancelUrl());
}
}
