AbjsExperienceDeleteConfirmForm.php in A/B Test JS 2.0.x
File
src/Form/AbjsExperienceDeleteConfirmForm.php
View source
<?php
namespace Drupal\abjs\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Database\Connection;
class AbjsExperienceDeleteConfirmForm extends ConfirmFormBase {
use StringTranslationTrait;
protected $id;
protected $database;
public function __construct(Connection $database) {
$this->database = $database;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('database'));
}
public function getFormId() {
return 'abjs_experience_delete_confirm';
}
public function getQuestion() {
return $this
->t('Do you want to delete experience %id?', [
'%id' => $this->id,
]);
}
public function getCancelUrl() {
return new Url('abjs.experience_admin');
}
public function getDescription() {
return $this
->t('This action cannot be undone.');
}
public function getConfirmText() {
return $this
->t('Delete');
}
public function getCancelText() {
return $this
->t('Cancel');
}
public function buildForm(array $form, FormStateInterface $form_state, $eid = NULL) {
$this->id = $eid;
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->database
->delete('abjs_experience')
->condition('eid', $this->id)
->execute();
$this->database
->delete('abjs_test_experience')
->condition('eid', $this->id)
->execute();
$this
->messenger()
->addMessage($this
->t('Experience %id has been deleted.', [
'%id' => $this->id,
]));
$form_state
->setRedirect('abjs.experience_admin');
}
}