Updated Drupal to 8.6. This goes with the following updates because it's possible...
[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  * @internal
15  */
16 class DeleteForm extends ConfirmFormBase {
17
18   /**
19    * The alias storage service.
20    *
21    * @var \Drupal\Core\Path\AliasStorageInterface
22    */
23   protected $aliasStorage;
24
25   /**
26    * The path alias being deleted.
27    *
28    * @var array
29    */
30   protected $pathAlias;
31
32   /**
33    * Constructs a \Drupal\path\Form\DeleteForm object.
34    *
35    * @param \Drupal\Core\Path\AliasStorageInterface $alias_storage
36    *   The alias storage service.
37    */
38   public function __construct(AliasStorageInterface $alias_storage) {
39     $this->aliasStorage = $alias_storage;
40   }
41
42   /**
43    * {@inheritdoc}
44    */
45   public static function create(ContainerInterface $container) {
46     return new static(
47       $container->get('path.alias_storage')
48     );
49   }
50
51   /**
52    * {@inheritdoc}
53    */
54   public function getFormId() {
55     return 'path_alias_delete';
56   }
57
58   /**
59    * {@inheritdoc}
60    */
61   public function getQuestion() {
62     return t('Are you sure you want to delete path alias %title?', ['%title' => $this->pathAlias['alias']]);
63   }
64
65   /**
66    * {@inheritdoc}
67    */
68   public function getCancelUrl() {
69     return new Url('path.admin_overview');
70   }
71
72   /**
73    * {@inheritdoc}
74    */
75   public function buildForm(array $form, FormStateInterface $form_state, $pid = NULL) {
76     $this->pathAlias = $this->aliasStorage->load(['pid' => $pid]);
77
78     $form = parent::buildForm($form, $form_state);
79
80     return $form;
81   }
82
83   /**
84    * {@inheritdoc}
85    */
86   public function submitForm(array &$form, FormStateInterface $form_state) {
87     $this->aliasStorage->delete(['pid' => $this->pathAlias['pid']]);
88
89     $form_state->setRedirect('path.admin_overview');
90   }
91
92 }