Commit bce56a17 authored by catch's avatar catch
Browse files

Issue #1946444 by kim.pepper: Convert confirm_form() in path.admin.inc to the new form interface.

parent c221f346
<?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';
}
}
......@@ -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.
*
......
......@@ -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',
......
path_delete:
pattern: 'admin/config/search/path/delete/{pid}'
defaults:
_form: '\Drupal\path\Form\DeleteForm'
requirements:
_permission: 'administer url aliases'
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment