Oauth2TokenDeleteForm.php in Simple OAuth (OAuth2) & OpenID Connect 8.4
File
src/Entity/Form/Oauth2TokenDeleteForm.php
View source
<?php
namespace Drupal\simple_oauth\Entity\Form;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Entity\ContentEntityConfirmFormBase;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
class Oauth2TokenDeleteForm extends ContentEntityConfirmFormBase {
protected $messenger;
public function __construct(EntityRepositoryInterface $entity_repository, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, TimeInterface $time = NULL, MessengerInterface $messenger) {
parent::__construct($entity_repository, $entity_type_bundle_info, $time);
$this->messenger = $messenger;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('entity.repository'), $container
->get('entity_type.bundle.info'), $container
->get('datetime.time'), $container
->get('messenger'));
}
public function getQuestion() {
return $this
->t('Are you sure you want to delete entity %name?', [
'%name' => $this->entity
->label(),
]);
}
public function getCancelUrl() {
return $this
->getEntity()
->toUrl('canonical');
}
public function getConfirmText() {
return $this
->t('Delete');
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->entity
->delete();
$this->messenger
->addMessage($this
->t('content @type: deleted @label.', [
'@type' => $this->entity
->bundle(),
'@label' => $this->entity
->label(),
]));
$form_state
->setRedirectUrl(new Url('entity.oauth2_token.collection'));
}
}