bd25f90a812dfbe514f6f97f088b3cb9eb59d6bc
[yaffs-website] / web / core / modules / path / src / Form / DeleteForm.php
1 <?php
2
3 namespace Drupal\path\Form;
4
5 use Drupal\Core\Form\ConfirmFormBase;
6 use Drupal\Core\Form\FormStateInterface;
7 use Drupal\Core\Path\AliasStorageInterface;
8 use Drupal\Core\Url;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
10
11 /**
12  * Builds the form to delete a path alias.
13  */
14 class DeleteForm extends ConfirmFormBase {
15
16   /**
17    * The alias storage service.
18    *
19    * @var \Drupal\Core\Path\AliasStorageInterface
20    */
21   protected $aliasStorage;
22
23   /**
24    * The path alias being deleted.
25    *
26    * @var array
27    */
28   protected $pathAlias;
29
30   /**
31    * Constructs a \Drupal\path\Form\DeleteForm object.
32    *
33    * @param \Drupal\Core\Path\AliasStorageInterface $alias_storage
34    *   The alias storage service.
35    */
36   public function __construct(AliasStorageInterface $alias_storage) {
37     $this->aliasStorage = $alias_storage;
38   }
39
40   /**
41    * {@inheritdoc}
42    */
43   public static function create(ContainerInterface $container) {
44     return new static(
45       $container->get('path.alias_storage')
46     );
47   }
48
49   /**
50    * {@inheritdoc}
51    */
52   public function getFormId() {
53     return 'path_alias_delete';
54   }
55
56   /**
57    * {@inheritdoc}
58    */
59   public function getQuestion() {
60     return t('Are you sure you want to delete path alias %title?', ['%title' => $this->pathAlias['alias']]);
61   }
62
63   /**
64    * {@inheritdoc}
65    */
66   public function getCancelUrl() {
67     return new Url('path.admin_overview');
68   }
69
70   /**
71    * {@inheritdoc}
72    */
73   public function buildForm(array $form, FormStateInterface $form_state, $pid = NULL) {
74     $this->pathAlias = $this->aliasStorage->load(['pid' => $pid]);
75
76     $form = parent::buildForm($form, $form_state);
77
78     return $form;
79   }
80
81   /**
82    * {@inheritdoc}
83    */
84   public function submitForm(array &$form, FormStateInterface $form_state) {
85     $this->aliasStorage->delete(['pid' => $this->pathAlias['pid']]);
86
87     $form_state->setRedirect('path.admin_overview');
88   }
89
90 }