DirectoryDeleteForm.php in Private files download permission 8.2
File
src/Form/DirectoryDeleteForm.php
View source
<?php
namespace Drupal\pfdp\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Entity\EntityStorageException;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
class DirectoryDeleteForm extends EntityConfirmFormBase {
public function getQuestion() {
$pfdp_directory = $this->entity;
return $this
->t('Are you sure you want to delete the directory %path from the control list?', [
'%path' => $pfdp_directory->path,
]);
}
public function getCancelUrl() {
return new Url('entity.pfdp_directory');
}
public function getConfirmText() {
return $this
->t('Delete');
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$pfdp_directory = $this->entity;
try {
$pfdp_directory
->delete();
$this
->logger('pfdp')
->info('The directory %path was deleted successfully.', [
'%path' => $pfdp_directory->path,
]);
\Drupal::messenger()
->addStatus($this
->t('The directory %path was deleted successfully.', [
'%path' => $pfdp_directory->path,
]));
} catch (EntityStorageException $exception) {
$this
->logger('pfdp')
->error('The directory %path was not deleted.', [
'%path' => $pfdp_directory->path,
]);
\Drupal::messenger()
->addError($this
->t('The directory %path was not deleted.', [
'%path' => $pfdp_directory->path,
]));
}
$form_state
->setRedirectUrl($this
->getCancelUrl());
}
}