Commit b5757ec1 authored by Dries's avatar Dries
Browse files

- Patch #750290 by sivaji: add a confirm form for role deletion and cleaned up form handling.

parent 967f4a1b
......@@ -934,6 +934,7 @@ function user_admin_role($form, $form_state, $role) {
$form['actions']['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete role'),
'#submit' => array('user_admin_role_delete_submit'),
);
return $form;
......@@ -961,16 +962,15 @@ function user_admin_role_validate($form, &$form_state) {
}
}
/**
* Form submit handler for the user_admin_role() form.
*/
function user_admin_role_submit($form, &$form_state) {
$role = (object)$form_state['values'];
if ($form_state['values']['op'] == t('Save role')) {
user_role_save($role);
drupal_set_message(t('The role has been renamed.'));
}
elseif ($form_state['values']['op'] == t('Delete role')) {
user_role_delete((int) $form_state['values']['rid']);
drupal_set_message(t('The role has been deleted.'));
}
elseif ($form_state['values']['op'] == t('Add role')) {
user_role_save($role);
drupal_set_message(t('The role has been added.'));
......@@ -979,6 +979,33 @@ function user_admin_role_submit($form, &$form_state) {
return;
}
/**
* Form submit handler for the user_admin_role() form.
*/
function user_admin_role_delete_submit($form, &$form_state) {
$form_state['redirect'] = 'admin/people/permissions/roles/delete/' . $form_state['values']['rid'];
}
/**
* Form to confirm role delete operation.
*/
function user_admin_role_delete_confirm($form, &$form_state, $role) {
$form['rid'] = array(
'#type' => 'value',
'#value' => $role->rid,
);
return confirm_form($form, t('Are you sure you want to delete the role %name ?', array('%name' => $role->name)), 'admin/people/permissions/roles', t('This action cannot be undone.'), t('Delete'));
}
/**
* Form submit handler for user_admin_role_delete_confirm().
*/
function user_admin_role_delete_confirm_submit($form, &$form_state) {
user_role_delete((int) $form_state['values']['rid']);
drupal_set_message(t('The role has been deleted.'));
$form_state['redirect'] = 'admin/people/permissions/roles';
}
/**
* Theme user administration filter selector.
*
......
......@@ -1533,7 +1533,15 @@ function user_menu() {
'access arguments' => array(5),
'type' => MENU_CALLBACK,
);
$items['admin/people/permissions/roles/delete/%user_role'] = array(
'title' => 'Delete role',
'page callback' => 'drupal_get_form',
'page arguments' => array('user_admin_role_delete_confirm', 5),
'access callback' => 'user_role_edit_access',
'access arguments' => array(5),
'type' => MENU_CALLBACK,
'file' => 'user.admin.inc',
);
$items['admin/people/create'] = array(
'title' => 'Add user',
......
......@@ -1507,6 +1507,7 @@ class UserRoleAdminTestCase extends DrupalWebTestCase {
// Test deleting a role.
$this->drupalPost("admin/people/permissions/roles/edit/{$role->rid}", NULL, t('Delete role'));
$this->drupalPost(NULL, NULL, t('Delete'));
$this->assertText(t('The role has been deleted.'), t('The role has been deleted'));
$this->assertNoLinkByHref("admin/people/permissions/roles/edit/{$role->rid}", t('Role edit link removed.'));
$this->assertFalse(user_role_load_by_name($role_name), t('A deleted role can no longer be loaded.'));
......
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