DemoDeleteConfirm.php in Demonstration site (Sandbox / Snapshot) 8
File
src/Form/DemoDeleteConfirm.php
View source
<?php
namespace Drupal\demo\Form;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Url;
class DemoDeleteConfirm extends ConfirmFormBase {
public function getFormId() {
return 'demo_delete_confirm';
}
public $filename;
public function buildForm(array $form, FormStateInterface $form_state, $filename = NULL) {
$fileconfig = demo_get_fileconfig($filename);
if (!file_exists($fileconfig['infofile'])) {
\Drupal::messenger()
->addMessage(t('File not found'), 'error');
}
$form['filename'] = [
'#type' => 'value',
'#value' => $filename,
];
return parent::buildForm($form, $form_state);
}
public function validateForm(array &$form, FormStateInterface $form_state) {
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$files = demo_get_fileconfig($form_state
->getValue([
'filename',
]));
unlink($files['sqlfile']);
unlink($files['infofile']);
\Drupal::messenger()
->addMessage(t('Snapshot %title has been deleted.', [
'%title' => $form_state
->getValue([
'filename',
]),
]));
$form_state
->setRedirect('demo.manage_form');
}
public function getCancelUrl() {
return new Url('demo.manage_form');
}
public function getQuestion() {
return t('Do you want to delete this screenshot?');
}
public function getConfirmText() {
return t('Delete');
}
}
Classes
Name |
Description |
DemoDeleteConfirm |
This class return the demo_delete_confirm, a form where you will be asked to be sure to delete your config file. |