Issue #1848874 by sun: Clean up and simplify user cancel methods and processing.
parent
26902ff184
commit
e4bd0c4537
|
@ -14,15 +14,6 @@ use Drupal\simpletest\WebTestBase;
|
|||
*/
|
||||
class UserCancelTest extends WebTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('comment');
|
||||
|
||||
protected $profile = 'standard';
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Cancel account',
|
||||
|
@ -31,6 +22,12 @@ class UserCancelTest extends WebTestBase {
|
|||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to cancel account without permission.
|
||||
*/
|
||||
|
@ -277,6 +274,8 @@ class UserCancelTest extends WebTestBase {
|
|||
*/
|
||||
function testUserDelete() {
|
||||
config('user.settings')->set('cancel_method', 'user_cancel_delete')->save();
|
||||
module_enable(array('comment'));
|
||||
$this->resetAll();
|
||||
|
||||
// Create a user.
|
||||
$account = $this->drupalCreateUser(array('cancel account', 'post comments', 'skip comment approval'));
|
||||
|
|
|
@ -346,23 +346,20 @@ function user_admin_settings($form, &$form_state) {
|
|||
'#default_value' => $config->get('verify_mail'),
|
||||
'#description' => t('New users will be required to validate their e-mail address prior to logging into the site, and will be assigned a system-generated password. With this setting disabled, users will be logged in immediately upon registering, and may select their own passwords during registration.')
|
||||
);
|
||||
module_load_include('inc', 'user', 'user.pages');
|
||||
form_load_include($form_state, 'inc', 'user', 'user.pages');
|
||||
$form['registration_cancellation']['user_cancel_method'] = array(
|
||||
'#type' => 'item',
|
||||
'#type' => 'radios',
|
||||
'#title' => t('When cancelling a user account'),
|
||||
'#default_value' => $config->get('cancel_method'),
|
||||
'#description' => t('Users with the %select-cancel-method or %administer-users <a href="@permissions-url">permissions</a> can override this default method.', array('%select-cancel-method' => t('Select method for cancelling account'), '%administer-users' => t('Administer users'), '@permissions-url' => url('admin/people/permissions'))),
|
||||
);
|
||||
$form['registration_cancellation']['user_cancel_method'] += user_cancel_methods();
|
||||
foreach (element_children($form['registration_cancellation']['user_cancel_method']) as $element) {
|
||||
// Remove all account cancellation methods that have #access defined, as
|
||||
// those cannot be configured as default method.
|
||||
if (isset($form['registration_cancellation']['user_cancel_method'][$element]['#access'])) {
|
||||
$form['registration_cancellation']['user_cancel_method'][$element]['#access'] = FALSE;
|
||||
}
|
||||
// Remove the description (only displayed on the confirmation form).
|
||||
else {
|
||||
unset($form['registration_cancellation']['user_cancel_method'][$element]['#description']);
|
||||
foreach (element_children($form['registration_cancellation']['user_cancel_method']) as $key) {
|
||||
// All account cancellation methods that specify #access cannot be
|
||||
// configured as default method.
|
||||
// @see hook_user_cancel_methods_alter()
|
||||
if (isset($form['registration_cancellation']['user_cancel_method'][$key]['#access'])) {
|
||||
$form['registration_cancellation']['user_cancel_method'][$key]['#access'] = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -143,8 +143,8 @@ function hook_user_cancel($edit, $account, $method) {
|
|||
* description is NOT used for the radio button, but instead should provide
|
||||
* additional explanation to the user seeking to cancel their account.
|
||||
* - access: (optional) A boolean value indicating whether the user can access
|
||||
* a method. If #access is defined, the method cannot be configured as default
|
||||
* method.
|
||||
* a method. If 'access' is defined, the method cannot be configured as
|
||||
* default method.
|
||||
*
|
||||
* @param $methods
|
||||
* An array containing user account cancellation methods, keyed by method id.
|
||||
|
|
|
@ -2475,16 +2475,12 @@ function user_multiple_cancel_confirm($form, &$form_state) {
|
|||
|
||||
$form['operation'] = array('#type' => 'hidden', '#value' => 'cancel');
|
||||
|
||||
module_load_include('inc', 'user', 'user.pages');
|
||||
form_load_include($form_state, 'inc', 'user', 'user.pages');
|
||||
$form['user_cancel_method'] = array(
|
||||
'#type' => 'item',
|
||||
'#type' => 'radios',
|
||||
'#title' => t('When cancelling these accounts'),
|
||||
);
|
||||
$form['user_cancel_method'] += user_cancel_methods();
|
||||
// Remove method descriptions.
|
||||
foreach (element_children($form['user_cancel_method']) as $element) {
|
||||
unset($form['user_cancel_method'][$element]['#description']);
|
||||
}
|
||||
|
||||
// Allow to send the account cancellation confirmation mail.
|
||||
$form['user_cancel_confirm'] = array(
|
||||
|
|
|
@ -232,7 +232,7 @@ function user_cancel_confirm_form($form, &$form_state, $account) {
|
|||
$admin_access = user_access('administer users');
|
||||
$can_select_method = $admin_access || user_access('select account cancellation method');
|
||||
$form['user_cancel_method'] = array(
|
||||
'#type' => 'item',
|
||||
'#type' => 'radios',
|
||||
'#title' => ($account->uid == $user->uid ? t('When cancelling your account') : t('When cancelling the account')),
|
||||
'#access' => $can_select_method,
|
||||
);
|
||||
|
@ -266,22 +266,15 @@ function user_cancel_confirm_form($form, &$form_state, $account) {
|
|||
else {
|
||||
$question = t('Are you sure you want to cancel the account %name?', array('%name' => $account->name));
|
||||
}
|
||||
$description = '';
|
||||
$default_method = config('user.settings')->get('cancel_method');
|
||||
$description = NULL;
|
||||
if ($can_select_method) {
|
||||
$description = t('Select the method to cancel the account above.');
|
||||
foreach (element_children($form['user_cancel_method']) as $element) {
|
||||
unset($form['user_cancel_method'][$element]['#description']);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// The radio button #description is used as description for the confirmation
|
||||
// form.
|
||||
foreach (element_children($form['user_cancel_method']) as $element) {
|
||||
if ($form['user_cancel_method'][$element]['#default_value'] == $form['user_cancel_method'][$element]['#return_value']) {
|
||||
$description = $form['user_cancel_method'][$element]['#description'];
|
||||
}
|
||||
unset($form['user_cancel_method'][$element]['#description']);
|
||||
}
|
||||
// Options supplied via user_cancel_methods() can have a custom
|
||||
// #confirm_description property for the confirmation form description.
|
||||
elseif (isset($form['user_cancel_method'][$default_method]['#confirm_description'])) {
|
||||
$description = $form['user_cancel_method'][$default_method]['#confirm_description'];
|
||||
}
|
||||
|
||||
// Always provide entity id in the same form key as in the entity edit form.
|
||||
|
@ -363,15 +356,22 @@ function user_cancel_methods() {
|
|||
drupal_alter('user_cancel_methods', $methods);
|
||||
|
||||
// Turn all methods into real form elements.
|
||||
$default_method = config('user.settings')->get('cancel_method');
|
||||
$form = array(
|
||||
'#options' => array(),
|
||||
'#default_value' => $default_method,
|
||||
);
|
||||
foreach ($methods as $name => $method) {
|
||||
$form[$name] = array(
|
||||
'#type' => 'radio',
|
||||
'#title' => $method['title'],
|
||||
'#description' => (isset($method['description']) ? $method['description'] : NULL),
|
||||
'#return_value' => $name,
|
||||
'#default_value' => config('user.settings')->get('cancel_method'),
|
||||
'#parents' => array('user_cancel_method'),
|
||||
);
|
||||
$form['#options'][$name] = $method['title'];
|
||||
// Add the description for the confirmation form. This description is never
|
||||
// shown for the cancel method option, only on the confirmation form.
|
||||
// Therefore, we use a custom #confirm_description property.
|
||||
if (isset($method['description'])) {
|
||||
$form[$name]['#confirm_description'] = $method['description'];
|
||||
}
|
||||
if (isset($method['access'])) {
|
||||
$form[$name]['#access'] = $method['access'];
|
||||
}
|
||||
}
|
||||
return $form;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue