diff --git a/core/modules/user/lib/Drupal/user/Tests/UserCancelTest.php b/core/modules/user/lib/Drupal/user/Tests/UserCancelTest.php index 58975e8b8caaacfafd863a3f27433bdb62265f25..e9f3f6c3ba63d553b3cc30be9905624aef97936c 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserCancelTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserCancelTest.php @@ -14,15 +14,6 @@ */ 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 @@ public static function getInfo() { ); } + function setUp() { + parent::setUp(); + + $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); + } + /** * Attempt to cancel account without permission. */ @@ -277,6 +274,8 @@ function testUserAnonymize() { */ 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')); diff --git a/core/modules/user/user.admin.inc b/core/modules/user/user.admin.inc index 3668aaef93845f0e9ff35aed1d89e2cc7246c195..06ac8d25fb2c48acb119d650adc65cf5df724a33 100644 --- a/core/modules/user/user.admin.inc +++ b/core/modules/user/user.admin.inc @@ -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; } } diff --git a/core/modules/user/user.api.php b/core/modules/user/user.api.php index 3dfb8ea08f3d8a851793eed3f6de8d075fbc626b..1c68427068ac12263587082e7954f122903ec68b 100644 --- a/core/modules/user/user.api.php +++ b/core/modules/user/user.api.php @@ -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. diff --git a/core/modules/user/user.module b/core/modules/user/user.module index ec43ade16ea9049ba9f2cb9ffb325171caedb133..7dabb6d093977898d38a0afe42a16b8a228fb807 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -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( diff --git a/core/modules/user/user.pages.inc b/core/modules/user/user.pages.inc index d45112d539fb07e1fc56bac0ad1340c8a054b75a..553f45590c070a4fae2446586450201e623b2038 100644 --- a/core/modules/user/user.pages.inc +++ b/core/modules/user/user.pages.inc @@ -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; }