Commit 198ec98f authored by Steven Wittens's avatar Steven Wittens

#18329: Unify confirmation messages (and make them themable)

parent 96211c61
......@@ -849,6 +849,57 @@ function theme_blocks($region) {
}
return $output;
}
/**
* Output a confirmation form
*
* This function outputs a complete form for confirming an action. A link is
* offered to go back to the item that is being changed in case the user changes
* his/her mind.
*
* You should use $_POST['edit'][$name] (where $name is usually 'confirm') to
* check if the confirmation was succesful.
*
* @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.
* @param $description
* Additional text to display (defaults to "This action cannot be undone.").
* @param $yes
* A caption for the button which confirms the action (e.g. "Delete",
* "Replace", ...).
* @param $no
* A caption for the link which denies the action (e.g. "Cancel").
* @param $extra
* Additional HTML to inject into the form, for example form_hidden()s.
* @param $name
* The internal name used to refer to the confirmation item.
* @return
* A themed HTML string representing the form.
*/
function theme_confirm($question, $path, $description = NULL, $yes = NULL, $no = NULL, $extra = NULL, $name = 'confirm') {
drupal_set_title($question);
if (is_null($description)) {
$description = t('This action cannot be undone.');
}
$output .= '<p>'. $description ."</p>\n";
if (!is_null($extra)) {
$output .= $extra;
}
$output .= '<div class="container-inline">';
$output .= form_submit($yes ? $yes : t('Confirm'));
$output .= l($no ? $no : t('Cancel'), $path);
$output .= "</div>\n";
$output .= form_hidden($name, 1);
return form($output, 'post', NULL, array('class' => 'confirmation'));
}
/**
* @} End of "defgroup themeable".
*/
......
......@@ -312,18 +312,20 @@ function block_box_add() {
function block_box_delete($bid = 0) {
$op = $_POST['op'];
$box = block_box_get($bid);
$info = $box['info'] ? $box['info'] : $box['title'];
switch ($op) {
case t('Delete'):
db_query('DELETE FROM {boxes} WHERE bid = %d', $bid);
drupal_set_message(t('The block %name has been deleted.', array('%name' => '<em>'. $box['info'] .'</em>')));
cache_clear_all();
drupal_goto('admin/block');
default:
$form = '<p>'. t('Are you sure you want to delete the block %name?', array('%name' => '<em>'. $box['info'] .'</em>')) ."</p>\n";
$form .= form_submit(t('Delete'));
$output = form($form);
if ($_POST['edit']['confirm']) {
db_query('DELETE FROM {boxes} WHERE bid = %d', $bid);
drupal_set_message(t('The block %name has been deleted.', array('%name' => '<em>'. $info .'</em>')));
cache_clear_all();
drupal_goto('admin/block');
}
else {
$output = theme('confirm',
t('Are you sure you want to delete the block %name?', array('%name' => '<em>'. $info .'</em>')),
'admin/block',
NULL,
t('Delete'));
}
print theme('page', $output);
......
......@@ -312,18 +312,20 @@ function block_box_add() {
function block_box_delete($bid = 0) {
$op = $_POST['op'];
$box = block_box_get($bid);
$info = $box['info'] ? $box['info'] : $box['title'];
switch ($op) {
case t('Delete'):
db_query('DELETE FROM {boxes} WHERE bid = %d', $bid);
drupal_set_message(t('The block %name has been deleted.', array('%name' => '<em>'. $box['info'] .'</em>')));
cache_clear_all();
drupal_goto('admin/block');
default:
$form = '<p>'. t('Are you sure you want to delete the block %name?', array('%name' => '<em>'. $box['info'] .'</em>')) ."</p>\n";
$form .= form_submit(t('Delete'));
$output = form($form);
if ($_POST['edit']['confirm']) {
db_query('DELETE FROM {boxes} WHERE bid = %d', $bid);
drupal_set_message(t('The block %name has been deleted.', array('%name' => '<em>'. $info .'</em>')));
cache_clear_all();
drupal_goto('admin/block');
}
else {
$output = theme('confirm',
t('Are you sure you want to delete the block %name?', array('%name' => '<em>'. $info .'</em>')),
'admin/block',
NULL,
t('Delete'));
}
print theme('page', $output);
......
......@@ -951,7 +951,7 @@ function comment_delete($cid) {
// We'll only delete if the user has confirmed the
// deletion using the form in our else clause below.
if ($comment->cid && $_POST['op'] == t('Delete')) {
if ($comment->cid && $_POST['edit']['confirm']) {
drupal_set_message(t('The comment and all its replies have been deleted.'));
// Delete comment and its replies.
......@@ -966,11 +966,15 @@ function comment_delete($cid) {
}
else if ($comment->cid) {
drupal_set_message(t('Do you want to delete this comment and all its replies?'));
$output = theme('confirm',
t('Are you sure you want to delete the comment %title?', array('%title' => '<em>'. $comment->subject .'</em>')),
'node/'. $comment->nid,
t('Any replies to this comment will be lost. This action cannot be undone.'),
t('Delete'));
// Show comment that is being deleted
$comment->comment = check_output($comment->comment, $comment->format);
$output = theme('comment', $comment);
$output .= form_submit(t('Delete'));
$output = form($output);
$output .= theme('comment', $comment);
}
else {
drupal_set_message(t('The comment no longer exists.'));
......
......@@ -951,7 +951,7 @@ function comment_delete($cid) {
// We'll only delete if the user has confirmed the
// deletion using the form in our else clause below.
if ($comment->cid && $_POST['op'] == t('Delete')) {
if ($comment->cid && $_POST['edit']['confirm']) {
drupal_set_message(t('The comment and all its replies have been deleted.'));
// Delete comment and its replies.
......@@ -966,11 +966,15 @@ function comment_delete($cid) {
}
else if ($comment->cid) {
drupal_set_message(t('Do you want to delete this comment and all its replies?'));
$output = theme('confirm',
t('Are you sure you want to delete the comment %title?', array('%title' => '<em>'. $comment->subject .'</em>')),
'node/'. $comment->nid,
t('Any replies to this comment will be lost. This action cannot be undone.'),
t('Delete'));
// Show comment that is being deleted
$comment->comment = check_output($comment->comment, $comment->format);
$output = theme('comment', $comment);
$output .= form_submit(t('Delete'));
$output = form($output);
$output .= theme('comment', $comment);
}
else {
drupal_set_message(t('The comment no longer exists.'));
......
......@@ -377,7 +377,7 @@ function filter_admin_add() {
*/
function filter_admin_delete() {
$edit = $_POST['edit'];
if ($_POST['op'] == t('Delete')) {
if ($edit['confirm']) {
if ($edit['format'] != variable_get('filter_default_format', 1)) {
db_query("DELETE FROM {filter_formats} WHERE format = %d", $edit['format']);
db_query("DELETE FROM {filters} WHERE format = %d", $edit['format']);
......@@ -397,11 +397,16 @@ function filter_admin_delete() {
$format = arg(3);
$format = db_fetch_object(db_query('SELECT * FROM {filter_formats} WHERE format = %d', $format));
$form .= form_hidden('format', $format->format);
$form .= form_hidden('name', $format->name);
$form .= '<p>'. t('Are you sure you want to delete the input format %format? If you have any content left in this input format, it will be switched to the default input format.', array('%format' => '<em>'. $format->name .'</em>')) ."</p>\n";
$form .= form_submit(t('Delete'));
print theme('page', form($form));
$extra = form_hidden('format', $format->format);
$extra .= form_hidden('name', $format->name);
$output = theme('confirm',
t('Are you sure you want to delete the input format %format?', array('%format' => '<em>'. $format->name .'</em>')),
'admin/filters',
t('If you have any content left in this input format, it will be switched to the default input format. This action cannot be undone.'),
t('Delete'),
t('Cancel'),
$extra);
print theme('page', $output);
}
/**
......
......@@ -377,7 +377,7 @@ function filter_admin_add() {
*/
function filter_admin_delete() {
$edit = $_POST['edit'];
if ($_POST['op'] == t('Delete')) {
if ($edit['confirm']) {
if ($edit['format'] != variable_get('filter_default_format', 1)) {
db_query("DELETE FROM {filter_formats} WHERE format = %d", $edit['format']);
db_query("DELETE FROM {filters} WHERE format = %d", $edit['format']);
......@@ -397,11 +397,16 @@ function filter_admin_delete() {
$format = arg(3);
$format = db_fetch_object(db_query('SELECT * FROM {filter_formats} WHERE format = %d', $format));
$form .= form_hidden('format', $format->format);
$form .= form_hidden('name', $format->name);
$form .= '<p>'. t('Are you sure you want to delete the input format %format? If you have any content left in this input format, it will be switched to the default input format.', array('%format' => '<em>'. $format->name .'</em>')) ."</p>\n";
$form .= form_submit(t('Delete'));
print theme('page', form($form));
$extra = form_hidden('format', $format->format);
$extra .= form_hidden('name', $format->name);
$output = theme('confirm',
t('Are you sure you want to delete the input format %format?', array('%format' => '<em>'. $format->name .'</em>')),
'admin/filters',
t('If you have any content left in this input format, it will be switched to the default input format. This action cannot be undone.'),
t('Delete'),
t('Cancel'),
$extra);
print theme('page', $output);
}
/**
......
......@@ -126,14 +126,17 @@ function forum_taxonomy($op, $type, $object) {
* @param $tid ID of the term to be deleted
*/
function _forum_confirm_del($tid) {
$term = taxonomy_get_term($tid);
$form .= form_hidden('confirm', 1);
$form .= form_hidden('tid', $tid);
$form .= form_submit(t('Delete'));
$form .= form_submit(t('Cancel'));
$term = taxonomy_get_term($tid);
return form(form_item(t('Delete "%name"', array('%name' => $term->name)), $form, t('Deleteing a forum or container will delete all sub-forums as well. Are you sure you want to delete?')));
$extra = form_hidden('tid', $tid);
$output = theme('confirm',
t('Are you sure you want to delete the forum %name?', array('%name' => '<em>'. $term->name .'</em>')),
'admin/forums',
t('Deleting a forum or container will delete all sub-forums as well. This action cannot be undone.'),
t('Delete'),
t('Cancel'),
$extra);
print theme('page', $output);
}
/**
......
......@@ -126,14 +126,17 @@ function forum_taxonomy($op, $type, $object) {
* @param $tid ID of the term to be deleted
*/
function _forum_confirm_del($tid) {
$term = taxonomy_get_term($tid);
$form .= form_hidden('confirm', 1);
$form .= form_hidden('tid', $tid);
$form .= form_submit(t('Delete'));
$form .= form_submit(t('Cancel'));
$term = taxonomy_get_term($tid);
return form(form_item(t('Delete "%name"', array('%name' => $term->name)), $form, t('Deleteing a forum or container will delete all sub-forums as well. Are you sure you want to delete?')));
$extra = form_hidden('tid', $tid);
$output = theme('confirm',
t('Are you sure you want to delete the forum %name?', array('%name' => '<em>'. $term->name .'</em>')),
'admin/forums',
t('Deleting a forum or container will delete all sub-forums as well. This action cannot be undone.'),
t('Delete'),
t('Cancel'),
$extra);
print theme('page', $output);
}
/**
......
......@@ -260,44 +260,28 @@ function locale_admin_manage() {
include_once 'includes/locale.inc';
$edit = &$_POST['edit'];
switch ($_POST['op']) {
if ($_POST['op'] == t('Save configuration')) {
// Save changes to existing languages
case t('Save configuration'):
$languages = locale_supported_languages(FALSE, TRUE);
foreach($languages['name'] as $key => $value) {
if ($edit['sitedefault'] == $key) {
$edit['enabled'][$key] = 1; // autoenable the default language
}
if ($key == 'en') {
// Disallow name change for English locale
db_query("UPDATE {locales_meta} SET isdefault = %d, enabled = %d WHERE locale = 'en'", ($edit['sitedefault'] == $key), $edit['enabled'][$key]);
}
else {
db_query("UPDATE {locales_meta} SET name = '%s', isdefault = %d, enabled = %d WHERE locale = '%s'", $edit['name'][$key], ($edit['sitedefault'] == $key), $edit['enabled'][$key], $key);
}
$languages = locale_supported_languages(FALSE, TRUE);
foreach($languages['name'] as $key => $value) {
if ($edit['sitedefault'] == $key) {
$edit['enabled'][$key] = 1; // autoenable the default language
}
// Changing the locale settings impacts the interface:
cache_clear_all();
break;
// Remove existing language
case t('Delete'):
$languages = locale_supported_languages(FALSE, TRUE);
if (isset($languages['name'][$edit['langcode']])) {
db_query("DELETE FROM {locales_meta} WHERE locale = '%s'", $edit['langcode']);
db_query("DELETE FROM {locales_target} WHERE locale = '%s'", $edit['langcode']);
$message = t('%locale language removed.', array('%locale' => '<em>'. t($languages['name'][$edit['langcode']]) .'</em>'));
drupal_set_message($message);
watchdog('locale', $message);
if ($key == 'en') {
// Disallow name change for English locale
db_query("UPDATE {locales_meta} SET isdefault = %d, enabled = %d WHERE locale = 'en'", ($edit['sitedefault'] == $key), $edit['enabled'][$key]);
}
else {
db_query("UPDATE {locales_meta} SET name = '%s', isdefault = %d, enabled = %d WHERE locale = '%s'", $edit['name'][$key], ($edit['sitedefault'] == $key), $edit['enabled'][$key], $key);
}
}
// Changing the locale settings impacts the interface:
cache_clear_all();
// Changing the locale settings impacts the interface:
cache_clear_all();
break;
drupal_goto('admin/locale/language/overview');
}
print theme('page', _locale_admin_manage_screen());
}
......@@ -307,6 +291,23 @@ function locale_admin_manage() {
function locale_admin_manage_delete_screen() {
include_once 'includes/locale.inc';
$langcode = arg(4);
$edit = $_POST['edit'];
// Check confirmation and if so, delete language
if ($edit['confirm']) {
$languages = locale_supported_languages(FALSE, TRUE);
if (isset($languages['name'][$edit['langcode']])) {
db_query("DELETE FROM {locales_meta} WHERE locale = '%s'", $edit['langcode']);
db_query("DELETE FROM {locales_target} WHERE locale = '%s'", $edit['langcode']);
$message = t('%locale language removed.', array('%locale' => '<em>'. t($languages['name'][$edit['langcode']]) .'</em>'));
drupal_set_message($message);
watchdog('locale', $message);
}
// Changing the locale settings impacts the interface:
cache_clear_all();
drupal_goto('admin/locale/language/overview');
}
// Do not allow deletion of English locale
if ($langcode == 'en') {
......@@ -315,10 +316,17 @@ function locale_admin_manage_delete_screen() {
}
// For other locales, warn user that data loss is ahead
$form = form_hidden('langcode', $langcode);
$form .= form_submit(t('Delete'));
$languages = locale_supported_languages(FALSE, TRUE);
print theme('page', form(form_item(t("Delete language '%name'", array('%name' => t($languages['name'][$langcode]))), $form, t('Are you sure you want to delete the language and all data associated with it?')), 'POST', url('admin/locale/language/overview')));
$extra = form_hidden('langcode', $langcode);
$output = theme('confirm',
t('Are you sure you want to delete the language %name?', array('%name' => '<em>'. t($languages['name'][$langcode]) .'</em>')),
'admin/locale/language/overview',
t('Deleting a language will remove all data associated with it. This action cannot be undone.'),
t('Delete'),
t('Cancel'),
$extra);
print theme('page', $output);
}
/**
......
......@@ -260,44 +260,28 @@ function locale_admin_manage() {
include_once 'includes/locale.inc';
$edit = &$_POST['edit'];
switch ($_POST['op']) {
if ($_POST['op'] == t('Save configuration')) {
// Save changes to existing languages
case t('Save configuration'):
$languages = locale_supported_languages(FALSE, TRUE);
foreach($languages['name'] as $key => $value) {
if ($edit['sitedefault'] == $key) {
$edit['enabled'][$key] = 1; // autoenable the default language
}
if ($key == 'en') {
// Disallow name change for English locale
db_query("UPDATE {locales_meta} SET isdefault = %d, enabled = %d WHERE locale = 'en'", ($edit['sitedefault'] == $key), $edit['enabled'][$key]);
}
else {
db_query("UPDATE {locales_meta} SET name = '%s', isdefault = %d, enabled = %d WHERE locale = '%s'", $edit['name'][$key], ($edit['sitedefault'] == $key), $edit['enabled'][$key], $key);
}
$languages = locale_supported_languages(FALSE, TRUE);
foreach($languages['name'] as $key => $value) {
if ($edit['sitedefault'] == $key) {
$edit['enabled'][$key] = 1; // autoenable the default language
}
// Changing the locale settings impacts the interface:
cache_clear_all();
break;
// Remove existing language
case t('Delete'):
$languages = locale_supported_languages(FALSE, TRUE);
if (isset($languages['name'][$edit['langcode']])) {
db_query("DELETE FROM {locales_meta} WHERE locale = '%s'", $edit['langcode']);
db_query("DELETE FROM {locales_target} WHERE locale = '%s'", $edit['langcode']);
$message = t('%locale language removed.', array('%locale' => '<em>'. t($languages['name'][$edit['langcode']]) .'</em>'));
drupal_set_message($message);
watchdog('locale', $message);
if ($key == 'en') {
// Disallow name change for English locale
db_query("UPDATE {locales_meta} SET isdefault = %d, enabled = %d WHERE locale = 'en'", ($edit['sitedefault'] == $key), $edit['enabled'][$key]);
}
else {
db_query("UPDATE {locales_meta} SET name = '%s', isdefault = %d, enabled = %d WHERE locale = '%s'", $edit['name'][$key], ($edit['sitedefault'] == $key), $edit['enabled'][$key], $key);
}
}
// Changing the locale settings impacts the interface:
cache_clear_all();
// Changing the locale settings impacts the interface:
cache_clear_all();
break;
drupal_goto('admin/locale/language/overview');
}
print theme('page', _locale_admin_manage_screen());
}
......@@ -307,6 +291,23 @@ function locale_admin_manage() {
function locale_admin_manage_delete_screen() {
include_once 'includes/locale.inc';
$langcode = arg(4);
$edit = $_POST['edit'];
// Check confirmation and if so, delete language
if ($edit['confirm']) {
$languages = locale_supported_languages(FALSE, TRUE);
if (isset($languages['name'][$edit['langcode']])) {
db_query("DELETE FROM {locales_meta} WHERE locale = '%s'", $edit['langcode']);
db_query("DELETE FROM {locales_target} WHERE locale = '%s'", $edit['langcode']);
$message = t('%locale language removed.', array('%locale' => '<em>'. t($languages['name'][$edit['langcode']]) .'</em>'));
drupal_set_message($message);
watchdog('locale', $message);
}
// Changing the locale settings impacts the interface:
cache_clear_all();
drupal_goto('admin/locale/language/overview');
}
// Do not allow deletion of English locale
if ($langcode == 'en') {
......@@ -315,10 +316,17 @@ function locale_admin_manage_delete_screen() {
}
// For other locales, warn user that data loss is ahead
$form = form_hidden('langcode', $langcode);
$form .= form_submit(t('Delete'));
$languages = locale_supported_languages(FALSE, TRUE);
print theme('page', form(form_item(t("Delete language '%name'", array('%name' => t($languages['name'][$langcode]))), $form, t('Are you sure you want to delete the language and all data associated with it?')), 'POST', url('admin/locale/language/overview')));
$extra = form_hidden('langcode', $langcode);
$output = theme('confirm',
t('Are you sure you want to delete the language %name?', array('%name' => '<em>'. t($languages['name'][$langcode]) .'</em>')),
'admin/locale/language/overview',
t('Deleting a language will remove all data associated with it. This action cannot be undone.'),
t('Delete'),
t('Cancel'),
$extra);
print theme('page', $output);
}
/**
......
......@@ -113,17 +113,17 @@ function menu_overview() {
function menu_reset() {
$op = $_POST['op'];
switch ($op) {
case t('Reset'):
case t('Reset all'):
db_query('DELETE FROM {menu}');
drupal_set_message(t('All menu items reset.'));
drupal_goto('admin/menu');
break;
case t('Cancel'):
drupal_goto('admin/menu');
break;
default:
$output = '<p>'. t('Are you sure you want to reset all menu items to their default settings? Any custom menu items will be lost.') .'</p>';
$output .= form(form_submit(t('Reset')) . form_submit(t('Cancel')));
$output = theme('confirm',
t('Are you sure you want to reset all menu items to their default settings?', array('%item' => '<em>'. $title .'</em>')),
'admin/menu',
t('Any custom additions or changes to the menu will be lost.'),
t('Reset all'));
print theme('page', $output);
}
}
......@@ -164,12 +164,13 @@ function menu_reset_item($mid) {
drupal_set_message(t('Menu item reset.'));
drupal_goto('admin/menu');
break;
case t('Cancel'):
drupal_goto('admin/menu');
break;
default:
$output = '<p>'. t('Are you sure you want to reset this item to its default values?') .'</p>';
$output .= form(form_submit(t('Reset')) . form_submit(t('Cancel')));
$title = db_result(db_query('SELECT title FROM {menu} WHERE mid = %d', $mid));
$output = theme('confirm',
t('Are you sure you want to reset the item %item to its default values?', array('%item' => '<em>'. $title .'</em>')),
'admin/menu',
t('Any customizations will be lost. This action cannot be undone.'),
t('Reset'));
print theme('page', $output);
}
}
......@@ -179,18 +180,30 @@ function menu_reset_item($mid) {
*/
function menu_delete_item($mid) {
$op = $_POST['op'];
$result = db_query('SELECT type, title FROM {menu} WHERE mid = %d', $mid);
$menu = db_fetch_object($result);
if (!$menu) {
drupal_goto('admin/menu');
}
switch ($op) {
case t('Delete'):
db_query('DELETE FROM {menu} WHERE mid = %d', $mid);
drupal_set_message(t('Menu item deleted.'));
drupal_goto('admin/menu');
break;
case t('Cancel'):
if ($menu->type & MENU_IS_ROOT) {
drupal_set_message(t('Menu deleted.'));
}
else {
drupal_set_message(t('Menu item deleted.'));
}
drupal_goto('admin/menu');
break;
default:
$output = '<p>'. t('Are you sure you want to delete this custom menu item?') .'</p>';
$output .= form(form_submit(t('Delete')) . form_submit(t('Cancel')));
if ($menu->type & MENU_IS_ROOT) {
$message = t('Are you sure you want to delete the menu %item?', array('%item' => '<em>'. $menu->title .'</em>'));
}
else {
$message = t('Are you sure you want to delete the custom menu item %item?', array('%item' => '<em>'. $menu->title .'</em>'));
}
$output = theme('confirm', $message, 'admin/menu', t('This action cannot be undone.'), t('Delete'));
print theme('page', $output);
}
}
......
......@@ -113,17 +113,17 @@ function menu_overview() {
function menu_reset() {
$op = $_POST['op'];
switch ($op) {
case t('Reset'):
case t('Reset all'):
db_query('DELETE FROM {menu}');
drupal_set_message(t('All menu items reset.'));
drupal_goto('admin/menu');
break;
case t('Cancel'):
drupal_goto('admin/menu');
break;
default:
$output = '<p>'. t('Are you sure you want to reset all menu items to their default settings? Any custom menu items will be lost.') .'</p>';
$output .= form(form_submit(t('Reset')) . form_submit(t('Cancel')));
$output = theme('confirm',
t('Are you sure you want to reset all menu items to their default settings?', array('%item' => '<em>'. $title .'</em>')),
'admin/menu',
t('Any custom additions or changes to the menu will be lost.'),
t('Reset all'));
print theme('page', $output);
}
}
......@@ -164,12 +164,13 @@ function menu_reset_item($mid) {
drupal_set_message(t('Menu item reset.'));
drupal_goto('admin/menu');
break;
case t('Cancel'):
drupal_goto('admin/menu');
break;
default:
$output = '<p>'. t('Are you sure you want to reset this item to its default values?') .'</p>';
$output .= form(form_submit(t('Reset')) . form_submit(t('Cancel')));
$title = db_result(db_query('SELECT title FROM {menu} WHERE mid = %d', $mid));
$output = theme('confirm',
t('Are you sure you want to reset the item %item to its default values?', array('%item' => '<em>'. $title .'</em>')),
'admin/menu',