3 namespace Drupal\path\Form;
5 use Drupal\Core\Form\ConfirmFormBase;
6 use Drupal\Core\Form\FormStateInterface;
7 use Drupal\Core\Path\AliasStorageInterface;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
12 * Builds the form to delete a path alias.
16 class DeleteForm extends ConfirmFormBase {
19 * The alias storage service.
21 * @var \Drupal\Core\Path\AliasStorageInterface
23 protected $aliasStorage;
26 * The path alias being deleted.
33 * Constructs a \Drupal\path\Form\DeleteForm object.
35 * @param \Drupal\Core\Path\AliasStorageInterface $alias_storage
36 * The alias storage service.
38 public function __construct(AliasStorageInterface $alias_storage) {
39 $this->aliasStorage = $alias_storage;
45 public static function create(ContainerInterface $container) {
47 $container->get('path.alias_storage')
54 public function getFormId() {
55 return 'path_alias_delete';
61 public function getQuestion() {
62 return t('Are you sure you want to delete path alias %title?', ['%title' => $this->pathAlias['alias']]);
68 public function getCancelUrl() {
69 return new Url('path.admin_overview');
75 public function buildForm(array $form, FormStateInterface $form_state, $pid = NULL) {
76 $this->pathAlias = $this->aliasStorage->load(['pid' => $pid]);
78 $form = parent::buildForm($form, $form_state);
86 public function submitForm(array &$form, FormStateInterface $form_state) {
87 $this->aliasStorage->delete(['pid' => $this->pathAlias['pid']]);
89 $form_state->setRedirect('path.admin_overview');