Commit 7093495f authored by Steven Wittens's avatar Steven Wittens

#154046: Optimize confirm_form syntax for common usage (and fix some $form_state bugs).

parent 028c8e60
......@@ -2912,9 +2912,9 @@ function drupal_delete_add_query($query) {
*
* @param $confirm
* An associative array with the following key/value pairs:
* 'form' => Optional. An array representing the form elements to pass to the confirm form.
* 'question' => Optional. The question for the confirm form.
* 'path' => Optional. The cancellation path for the confirm form.
* 'form' => Optional. An array representing the form elements to pass to the confirm form.
* 'question' => Optional. The question for the confirm form.
* 'destination' => Optional. The destination path for form submissions and form cancellations.
*
* Also, any valid options from the $options argument of confirm_form() may be passed,
* and they will be passed through to the confirm form.
......@@ -2922,9 +2922,8 @@ function drupal_delete_add_query($query) {
* array(
* 'form' => $form,
* 'question' => t('Are you sure you want to delete these items?'),
* 'path' => 'admin/content/node',
* 'yes' => t('Delete all'),
* 'destination' => 'admin/content/node',
* 'yes' => t('Delete all'),
* )
* );
*/
......@@ -3142,8 +3141,8 @@ function _drupal_delete($op, $id = '') {
// Generate the confirm form if any packages remain.
if ($count) {
$question = isset($args['question']) ? $args['question'] : t('Delete the item?');
$path = isset($args['path']) ? $args['path'] : 'node';
unset($args['question'], $args['path']);
$path = isset($args['destination']) ? $args['destination'] : '<front>';
unset($args['question'], $args['destination']);
$args['name'] = 'delete';
// Submit handler - triggers execute operation for the API.
$form['#submit'] = array('delete_confirm_submit');
......@@ -3154,12 +3153,12 @@ function _drupal_delete($op, $id = '') {
drupal_goto($abort_destination);
}
// Fallback to cancel path.
elseif (isset($args['path'])) {
drupal_goto($args['path']);
elseif (isset($args['cancel'])) {
drupal_goto($args['cancel']);
}
// Last fallback, front page.
// Last fallback, submit destination.
else {
drupal_goto('<front>');
drupal_goto($path);
}
}
}
......
......@@ -1114,9 +1114,8 @@ function comment_delete(&$form_state, $cid = NULL) {
return drupal_delete_confirm(
array(
'question' => t('Are you sure you want to delete the comment %title?', array('%title' => $comment->subject)),
'path' => 'node/'. $comment->nid,
'description' => t('Any replies to this comment will be lost. This action cannot be undone.'),
'destination' => 'node/'. $comment->nid,
'description' => t('Any replies to this comment will be lost. This action cannot be undone.'),
)
);
}
......@@ -1344,9 +1343,8 @@ function comment_multiple_delete_confirm(&$form_state) {
array(
'form' => $form,
'question' => t('Are you sure you want to delete these comments and all their children?'),
'path' => 'admin/content/comment',
'yes' => t('Delete all'),
'destination' => 'admin/content/comment',
'yes' => t('Delete all'),
)
);
}
......
......@@ -488,10 +488,11 @@ function menu_reset_item(&$form_state, $mlid) {
$options = array(
'description' => t('Any customizations will be lost. This action cannot be undone.'),
'yes' => t('Reset')
'yes' => t('Reset'),
'cancel' => 'admin/build/menu',
);
return confirm_form($form, t('Are you sure you want to reset the item %item to its default values?', array('%item' => $item['link_title'])), 'admin/build/menu', $options);
return confirm_form($form, t('Are you sure you want to reset the item %item to its default values?', array('%item' => $item['link_title'])), 'admin/build/menu/navigation', $options);
}
else {
drupal_not_found();
......
......@@ -1743,9 +1743,8 @@ function node_multiple_delete_confirm(&$form_state) {
array(
'form' => $form,
'question' => t('Are you sure you want to delete these items?'),
'path' => 'admin/content/node',
'yes' => t('Delete all'),
'destination' => 'admin/content/node',
'yes' => t('Delete all'),
)
);
}
......@@ -2443,7 +2442,7 @@ function node_delete_confirm(&$form_state, $node) {
return drupal_delete_confirm(
array(
'question' => t('Are you sure you want to delete %title?', array('%title' => $node->title)),
'path' => isset($_GET['destination']) ? $_GET['destination'] : 'node/'. $node->nid,
'cancel' => isset($_GET['destination']) ? $_GET['destination'] : 'node/'. $node->nid,
'destination' => isset($_GET['destination']) ? $_GET['destination'] : '<front>',
)
);
......
......@@ -90,13 +90,14 @@ function path_admin_edit($pid = 0) {
/**
* Menu callback; confirms deleting an URL alias
**/
function path_admin_delete_confirm($pid) {
function path_admin_delete_confirm(&$form_state, $pid) {
$path = path_load($pid);
if (user_access('administer url aliases')) {
$form['pid'] = array('#type' => 'value', '#value' => $pid);
$options = array('cancel' => isset($_GET['destination']) ? $_GET['destination'] : 'admin/build/path');
$output = confirm_form($form,
t('Are you sure you want to delete path alias %title?', array('%title' => $path['dst'])),
isset($_GET['destination']) ? $_GET['destination'] : 'admin/build/path');
'admin/build/path', $options);
}
return $output;
}
......
......@@ -2426,9 +2426,11 @@ function system_node_type($op, $info) {
* @param $question
* The question to ask the user (e.g. "Are you sure you want to delete the
* block <em>foo</em>?").
* @param $path
* The page to go to if the user denies the action.
* Can be either a Drupal path, or an array with the keys 'path', 'query', 'fragment'.
* @param $destination
* The page to go to if the confirm form is submitted, or the action is cancelled.
* The value can be either a Drupal path, or an array with the keys 'path', 'query', 'fragment'.
*
* Note: If a custom submit handler is being used, return the destination from the handler.
* @param $options
* An associative array of options, with the following key/value pairs:
* 'description' => Additional text to display.
......@@ -2439,37 +2441,39 @@ function system_node_type($op, $info) {
* Default is "Cancel".
* 'name' => The internal name used to refer to the confirmation item.
* Default is "confirm".
* 'destination' => A destination page to go to after form submission -- the value can
* be of any form of the $goto argument accepted by drupal_redirect().
* 'cancel' => Set a custom path for cancelling the form, -- can be either a Drupal path,
* or an array with the keys 'path', 'query', 'fragment'.
*
* @return
* The form.
*/
function confirm_form($form, $question, $path, $options = array()) {
function confirm_form($form, $question, $destination, $options = array()) {
$description = isset($options['description']) ? $options['description'] : t('This action cannot be undone.');
$name = isset($options['name']) ? $options['name'] : 'confirm';
$cancel = isset($options['cancel']) ? $options['cancel'] : $destination;
// Prepare cancel link
$query = $fragment = NULL;
if (is_array($path)) {
$query = isset($path['query']) ? $path['query'] : NULL;
$fragment = isset($path['fragment']) ? $path['fragment'] : NULL;
$path = isset($path['path']) ? $path['path'] : NULL;
if (is_array($cancel)) {
$query = isset($cancel['query']) ? $cancel['query'] : NULL;
$fragment = isset($cancel['fragment']) ? $cancel['fragment'] : NULL;
$path = isset($cancel['path']) ? $cancel['path'] : NULL;
}
else {
$path = $cancel;
}
$cancel = l(isset($options['no']) ? $options['no'] : t('Cancel'), $path, array('query' => $query, 'fragment' => $fragment));
$cancel_link = l(isset($options['no']) ? $options['no'] : t('Cancel'), $path, array('query' => $query, 'fragment' => $fragment));
drupal_set_title($question);
$form['#attributes'] = array('class' => 'confirmation');
$form['description'] = array('#value' => $description);
$form[$name] = array('#type' => 'hidden', '#value' => 1);
if (isset($options['destination'])) {
$form['destination'] = array('#type' => 'value', '#value' => $options['destination']);
}
$form['destination'] = array('#type' => 'value', '#value' => $destination);
$form['actions'] = array('#prefix' => '<div class="container-inline">', '#suffix' => '</div>');
$form['actions']['submit'] = array('#type' => 'submit', '#value' => isset($options['yes']) ? $options['yes'] : t('Delete'));
$form['actions']['cancel'] = array('#value' => $cancel);
$form['actions']['cancel'] = array('#value' => $cancel_link);
$form['#theme'] = 'confirm_form';
return $form;
......
......@@ -1621,12 +1621,15 @@ function user_edit($form_state, $category = 'account') {
return $form;
}
function user_confirm_delete($name, $uid) {
$options = array('description' => t('All submissions made by this user will be attributed to the anonymous account. This action cannot be undone.'));
function user_confirm_delete(&$form_state, $name, $uid) {
$options = array(
'description' => t('All submissions made by this user will be attributed to the anonymous account. This action cannot be undone.'),
'cancel' => 'user/'. $uid,
);
return confirm_form(array(),
t('Are you sure you want to delete the account %name?', array('%name' => $name)),
'user/'. $uid,
'admin/user/user',
$options);
}
......
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