diff --git a/core/modules/user/lib/Drupal/user/AccountSettingsForm.php b/core/modules/user/lib/Drupal/user/AccountSettingsForm.php index c43dc6d..af09cd0 100644 --- a/core/modules/user/lib/Drupal/user/AccountSettingsForm.php +++ b/core/modules/user/lib/Drupal/user/AccountSettingsForm.php @@ -134,7 +134,6 @@ public function buildForm(array $form, array &$form_state) { '#title' => t('Enable password strength indicator'), '#default_value' => $config->get('password_strength'), ); - form_load_include($form_state, 'inc', 'user', 'user.pages'); $form['registration_cancellation']['user_cancel_method'] = array( '#type' => 'radios', '#title' => t('When cancelling a user account'), diff --git a/core/modules/user/lib/Drupal/user/Form/UserCancelForm.php b/core/modules/user/lib/Drupal/user/Form/UserCancelForm.php index acc5c8b..e30caf5 100644 --- a/core/modules/user/lib/Drupal/user/Form/UserCancelForm.php +++ b/core/modules/user/lib/Drupal/user/Form/UserCancelForm.php @@ -34,6 +34,13 @@ class UserCancelForm extends EntityNGConfirmFormBase implements EntityController protected $configFactory; /** + * The current user's ID. + * + * @var int + */ + protected $userId; + + /** * Constructs an EntityFormController object. * * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler @@ -61,8 +68,7 @@ public static function createInstance(ContainerInterface $container, $entity_typ * {@inheritdoc} */ public function getQuestion() { - global $user; - if ($this->entity->id() == $user->id()) { + if ($this->entity->id() == $this->userId) { return t('Are you sure you want to cancel your account?'); } return t('Are you sure you want to cancel the account %name?', array('%name' => $this->entity->label())); @@ -103,16 +109,14 @@ public function getConfirmText() { * {@inheritdoc} */ public function buildForm(array $form, array &$form_state, Request $request = NULL) { - // @todo move to proper place - form_load_include($form_state, 'inc', 'user', 'user.pages'); $this->cancelMethods = user_cancel_methods(); - global $user; + $this->userId = $request->attributes->get('account')->id(); // Display account cancellation method selection, if allowed. $admin_access = user_access('administer users'); $form['user_cancel_method'] = array( '#type' => 'radios', - '#title' => ($this->entity->id() == $user->id() ? t('When cancelling your account') : t('When cancelling the account')), + '#title' => ($this->entity->id() == $this->userId ? t('When cancelling your account') : t('When cancelling the account')), '#access' => $admin_access || user_access('select account cancellation method'), ); $form['user_cancel_method'] += $this->cancelMethods; @@ -120,7 +124,7 @@ public function buildForm(array $form, array &$form_state, Request $request = NU // Allow user administrators to skip the account cancellation confirmation // mail (by default), as long as they do not attempt to cancel their own // account. - $override_access = $admin_access && ($this->entity->id() != $user->id()); + $override_access = $admin_access && ($this->entity->id() != $this->userId); $form['user_cancel_confirm'] = array( '#type' => 'checkbox', '#title' => t('Require e-mail confirmation to cancel account.'), @@ -147,12 +151,10 @@ public function buildForm(array $form, array &$form_state, Request $request = NU * {@inheritdoc} */ public function submit(array $form, array &$form_state) { - global $user; - // Cancel account immediately, if the current user has administrative // privileges, no confirmation mail shall be sent, and the user does not // attempt to cancel the own account. - if (user_access('administer users') && empty($form_state['values']['user_cancel_confirm']) && $this->entity->id() != $user->id()) { + if (user_access('administer users') && empty($form_state['values']['user_cancel_confirm']) && $this->entity->id() != $this->userId) { user_cancel($form_state['values'], $this->entity->id(), $form_state['values']['user_cancel_method']); $form_state['redirect'] = 'admin/people'; diff --git a/core/modules/user/lib/Drupal/user/Form/UserMultipleCancelConfirm.php b/core/modules/user/lib/Drupal/user/Form/UserMultipleCancelConfirm.php index 5955b76..e4248e7 100644 --- a/core/modules/user/lib/Drupal/user/Form/UserMultipleCancelConfirm.php +++ b/core/modules/user/lib/Drupal/user/Form/UserMultipleCancelConfirm.php @@ -160,8 +160,6 @@ public function buildForm(array $form, array &$form_state, Request $request = NU '#title' => t('When cancelling these accounts'), ); - // @todo move to proper place - form_load_include($form_state, 'inc', 'user', 'user.pages'); $form['user_cancel_method'] += user_cancel_methods(); // Allow to send the account cancellation confirmation mail. @@ -187,10 +185,10 @@ public function buildForm(array $form, array &$form_state, Request $request = NU * {@inheritdoc} */ public function submitForm(array &$form, array &$form_state) { - global $user; + $current_user_id = $this->request->attributes->get('account')->id(); // Clear out the accounts from the temp store. - $this->tempStoreFactory->get('user_user_operations_cancel')->delete($user->id()); + $this->tempStoreFactory->get('user_user_operations_cancel')->delete($current_user_id); if ($form_state['values']['confirm']) { foreach ($form_state['values']['accounts'] as $uid => $value) { // Prevent programmatic form submissions from cancelling user 1. @@ -198,7 +196,7 @@ public function submitForm(array &$form, array &$form_state) { continue; } // Prevent user administrators from deleting themselves without confirmation. - if ($uid == $user->id()) { + if ($uid == $current_user_id) { $admin_form_mock = array(); $admin_form_state = $form_state; unset($admin_form_state['values']['user_cancel_confirm']); diff --git a/core/modules/user/user.module b/core/modules/user/user.module index ad5fbe1..7fb186b 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -1371,6 +1371,62 @@ function _user_cancel_session_regenerate() { } /** + * Helper function to return available account cancellation methods. + * + * See documentation of hook_user_cancel_methods_alter(). + * + * @return array + * An array containing all account cancellation methods as form elements. + * + * @see hook_user_cancel_methods_alter() + * @see user_admin_settings() + */ +function user_cancel_methods() { + $anonymous_name = config('user.settings')->get('anonymous'); + $methods = array( + 'user_cancel_block' => array( + 'title' => t('Disable the account and keep its content.'), + 'description' => t('Your account will be blocked and you will no longer be able to log in. All of your content will remain attributed to your user name.'), + ), + 'user_cancel_block_unpublish' => array( + 'title' => t('Disable the account and unpublish its content.'), + 'description' => t('Your account will be blocked and you will no longer be able to log in. All of your content will be hidden from everyone but administrators.'), + ), + 'user_cancel_reassign' => array( + 'title' => t('Delete the account and make its content belong to the %anonymous-name user.', array('%anonymous-name' => $anonymous_name)), + 'description' => t('Your account will be removed and all account information deleted. All of your content will be assigned to the %anonymous-name user.', array('%anonymous-name' => $anonymous_name)), + ), + 'user_cancel_delete' => array( + 'title' => t('Delete the account and its content.'), + 'description' => t('Your account will be removed and all account information deleted. All of your content will also be deleted.'), + 'access' => user_access('administer users'), + ), + ); + // Allow modules to customize account cancellation 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['#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; +} + +/** * Delete a user. * * @param $uid diff --git a/core/modules/user/user.pages.inc b/core/modules/user/user.pages.inc index 92e10bd..ece55bb 100644 --- a/core/modules/user/user.pages.inc +++ b/core/modules/user/user.pages.inc @@ -133,62 +133,6 @@ function user_edit_cancel_submit($form, &$form_state) { } /** - * Helper function to return available account cancellation methods. - * - * See documentation of hook_user_cancel_methods_alter(). - * - * @return - * An array containing all account cancellation methods as form elements. - * - * @see hook_user_cancel_methods_alter() - * @see user_admin_settings() - */ -function user_cancel_methods() { - $anonymous_name = config('user.settings')->get('anonymous'); - $methods = array( - 'user_cancel_block' => array( - 'title' => t('Disable the account and keep its content.'), - 'description' => t('Your account will be blocked and you will no longer be able to log in. All of your content will remain attributed to your user name.'), - ), - 'user_cancel_block_unpublish' => array( - 'title' => t('Disable the account and unpublish its content.'), - 'description' => t('Your account will be blocked and you will no longer be able to log in. All of your content will be hidden from everyone but administrators.'), - ), - 'user_cancel_reassign' => array( - 'title' => t('Delete the account and make its content belong to the %anonymous-name user.', array('%anonymous-name' => $anonymous_name)), - 'description' => t('Your account will be removed and all account information deleted. All of your content will be assigned to the %anonymous-name user.', array('%anonymous-name' => $anonymous_name)), - ), - 'user_cancel_delete' => array( - 'title' => t('Delete the account and its content.'), - 'description' => t('Your account will be removed and all account information deleted. All of your content will also be deleted.'), - 'access' => user_access('administer users'), - ), - ); - // Allow modules to customize account cancellation 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['#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; -} - -/** * Menu callback; Cancel a user account via e-mail confirmation link. * * @see user_cancel_confirm_form()