ApiKeyDeleteConfirmForm.php in Services API Key Authentication 8.2
File
src/Form/ApiKeyDeleteConfirmForm.php
View source
<?php
namespace Drupal\services_api_key_auth\Form;
use Drupal\Core\Entity\EntityDeleteForm;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ApiKeyDeleteConfirmForm extends EntityDeleteForm {
protected $messenger;
public function __construct(MessengerInterface $messenger) {
$this->messenger = $messenger;
}
public static function create(ContainerInterface $container) {
$messenger = $container
->get('messenger');
return new static($messenger);
}
public function getQuestion() {
return $this
->t('Are you sure you want to delete the Api Key %name?', [
'%name' => $this->entity
->label(),
]);
}
public function getDescription() {
return $this
->t('Deleting an api key for a user will prevent access for certain endpoints only.');
}
public function getCancelUrl() {
return new Url('entity.search_api_server.canonical', [
'search_api_server' => $this->entity
->id(),
]);
}
public function getConfirmText() {
return $this
->t('Delete');
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->entity
->delete();
$this->messenger
->addStatus($this
->t('The search server %name has been deleted.', [
'%name' => $this->entity
->label(),
]));
$form_state
->setRedirect('search_api.overview');
}
}