From bce56a17932140b2493faa7a3f6863569b9cb3c2 Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Sat, 6 Apr 2013 22:44:45 +0100
Subject: [PATCH] Issue #1946444 by kim.pepper: Convert confirm_form() in
 path.admin.inc to the new form interface.

---
 .../path/lib/Drupal/path/Form/DeleteForm.php  | 91 +++++++++++++++++++
 core/modules/path/path.admin.inc              | 31 -------
 core/modules/path/path.module                 |  5 +-
 core/modules/path/path.routing.yml            |  6 ++
 4 files changed, 98 insertions(+), 35 deletions(-)
 create mode 100644 core/modules/path/lib/Drupal/path/Form/DeleteForm.php
 create mode 100644 core/modules/path/path.routing.yml

diff --git a/core/modules/path/lib/Drupal/path/Form/DeleteForm.php b/core/modules/path/lib/Drupal/path/Form/DeleteForm.php
new file mode 100644
index 000000000000..0eb9b886e9a2
--- /dev/null
+++ b/core/modules/path/lib/Drupal/path/Form/DeleteForm.php
@@ -0,0 +1,91 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\path\Form\DeleteForm.
+ */
+
+namespace Drupal\path\Form;
+
+use Drupal\Core\Form\ConfirmFormBase;
+use Drupal\Core\ControllerInterface;
+use Drupal\Core\Path\Path;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
+/**
+ * Builds the form to delete a path alias.
+ */
+class DeleteForm extends ConfirmFormBase implements ControllerInterface {
+
+  /**
+   * The path crud service.
+   *
+   * @var Path $path
+   */
+  protected $path;
+
+  /**
+   * The path alias being deleted.
+   *
+   * @var array $pathAlias
+   */
+  protected $pathAlias;
+
+  /**
+   * Constructs a \Drupal\Core\Path\Path object.
+   *
+   * @param \Drupal\Core\Path\Path $path
+   *   The path crud service.
+   */
+  public function __construct(Path $path) {
+    $this->path = $path;
+  }
+
+  /**
+   * Implements \Drupal\Core\ControllerInterface::create().
+   */
+  public static function create(ContainerInterface $container) {
+    return new static(
+      $container->get('path.crud')
+    );
+  }
+
+  /**
+   * Implements \Drupal\Core\Form\FormInterface::getFormID().
+   */
+  public function getFormID() {
+    return 'path_alias_delete';
+  }
+
+  /**
+   * Implements \Drupal\Core\Form\ConfirmFormBase::getQuestion().
+   */
+  protected function getQuestion() {
+    return t('Are you sure you want to delete path alias %title?', array('%title' => $this->pathAlias['alias']));
+  }
+
+  /**
+   * Implements \Drupal\Core\Form\ConfirmFormBase::getCancelPath().
+   */
+  protected function getCancelPath() {
+    return 'admin/config/search/path';
+  }
+
+  /**
+   * Overrides \Drupal\Core\Form\ConfirmFormBase::buildForm().
+   */
+  public function buildForm(array $form, array &$form_state, $pid = NULL) {
+    $this->pathAlias = $this->path->load(array('pid' => $pid));
+
+    return parent::buildForm($form, $form_state);
+  }
+
+  /**
+   * Implements \Drupal\Core\Form\FormInterface::submitForm().
+   */
+  public function submitForm(array &$form, array &$form_state) {
+    $this->path->delete(array('pid' => $this->pathAlias['pid']));
+
+    $form_state['redirect'] = 'admin/config/search/path';
+  }
+}
diff --git a/core/modules/path/path.admin.inc b/core/modules/path/path.admin.inc
index 05354544bdc3..773431c0a2de 100644
--- a/core/modules/path/path.admin.inc
+++ b/core/modules/path/path.admin.inc
@@ -263,37 +263,6 @@ function path_admin_form_submit($form, &$form_state) {
   $form_state['redirect'] = 'admin/config/search/path';
 }
 
-/**
- * Form constructor for the path deletion form.
- *
- * @param $path
- *   The path alias that will be deleted.
- *
- * @see path_admin_delete_confirm_submit()
- */
-function path_admin_delete_confirm($form, &$form_state, $path) {
-  if (user_access('administer url aliases')) {
-    $form_state['path'] = $path;
-    return confirm_form(
-      $form,
-      t('Are you sure you want to delete path alias %title?',
-      array('%title' => $path['alias'])),
-      'admin/config/search/path'
-    );
-  }
-  return array();
-}
-
-/**
- * Form submission handler for path_admin_delete_confirm().
- */
-function path_admin_delete_confirm_submit($form, &$form_state) {
-  if ($form_state['values']['confirm']) {
-    drupal_container()->get('path.crud')->delete(array('pid' => $form_state['path']['pid']));
-    $form_state['redirect'] = 'admin/config/search/path';
-  }
-}
-
 /**
  * Form constructor for the path admin overview filter form.
  *
diff --git a/core/modules/path/path.module b/core/modules/path/path.module
index b6a38f6c647f..cee17ed595f7 100644
--- a/core/modules/path/path.module
+++ b/core/modules/path/path.module
@@ -77,10 +77,7 @@ function path_menu() {
   );
   $items['admin/config/search/path/delete/%path'] = array(
     'title' => 'Delete alias',
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('path_admin_delete_confirm', 5),
-    'access arguments' => array('administer url aliases'),
-    'file' => 'path.admin.inc',
+    'route_name' => 'path_delete',
   );
   $items['admin/config/search/path/add'] = array(
     'title' => 'Add alias',
diff --git a/core/modules/path/path.routing.yml b/core/modules/path/path.routing.yml
new file mode 100644
index 000000000000..dbc6883df379
--- /dev/null
+++ b/core/modules/path/path.routing.yml
@@ -0,0 +1,6 @@
+path_delete:
+  pattern: 'admin/config/search/path/delete/{pid}'
+  defaults:
+    _form: '\Drupal\path\Form\DeleteForm'
+  requirements:
+    _permission: 'administer url aliases'
-- 
GitLab