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.
14 class DeleteForm extends ConfirmFormBase {
17 * The alias storage service.
19 * @var AliasStorageInterface $path
21 protected $aliasStorage;
24 * The path alias being deleted.
26 * @var array $pathAlias
31 * Constructs a \Drupal\path\Form\DeleteForm object.
33 * @param \Drupal\Core\Path\AliasStorageInterface $alias_storage
34 * The alias storage service.
36 public function __construct(AliasStorageInterface $alias_storage) {
37 $this->aliasStorage = $alias_storage;
43 public static function create(ContainerInterface $container) {
45 $container->get('path.alias_storage')
52 public function getFormId() {
53 return 'path_alias_delete';
59 public function getQuestion() {
60 return t('Are you sure you want to delete path alias %title?', ['%title' => $this->pathAlias['alias']]);
66 public function getCancelUrl() {
67 return new Url('path.admin_overview');
73 public function buildForm(array $form, FormStateInterface $form_state, $pid = NULL) {
74 $this->pathAlias = $this->aliasStorage->load(['pid' => $pid]);
76 $form = parent::buildForm($form, $form_state);
84 public function submitForm(array &$form, FormStateInterface $form_state) {
85 $this->aliasStorage->delete(['pid' => $this->pathAlias['pid']]);
87 $form_state->setRedirect('path.admin_overview');