SavedSearchDeleteConfirmForm.php in Search API Saved Searches 8
File
src/Form/SavedSearchDeleteConfirmForm.php
View source
<?php
namespace Drupal\search_api_saved_searches\Form;
use Drupal\Core\Entity\ContentEntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
class SavedSearchDeleteConfirmForm extends ContentEntityConfirmFormBase {
protected $entity;
public function getQuestion() {
return $this
->t('Do you really want to delete this saved search?');
}
public function getCancelUrl() {
if (!empty($this->entity
->getOwnerId())) {
$redirect = '/user/' . $this->entity
->getOwnerId() . '/saved-searches';
return Url::fromUserInput($redirect);
}
else {
return Url::fromUri('internal:/');
}
}
public function getConfirmText() {
return $this
->t('Delete');
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->entity
->delete();
$this
->messenger()
->addStatus($this
->t('The saved search was successfully deleted.'));
$form_state
->setRedirectUrl($this
->getCancelUrl());
}
}