diff --git a/core/modules/user/lib/Drupal/user/Form/UserCancelForm.php b/core/modules/user/lib/Drupal/user/Form/UserCancelForm.php index e18d830..4730986 100644 --- a/core/modules/user/lib/Drupal/user/Form/UserCancelForm.php +++ b/core/modules/user/lib/Drupal/user/Form/UserCancelForm.php @@ -10,9 +10,7 @@ use Drupal\Core\Config\ConfigFactory; use Drupal\Core\Entity\EntityControllerInterface; use Drupal\Core\Entity\EntityNGConfirmFormBase; -use Drupal\Core\Extension\ModuleHandlerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\HttpFoundation\Request; /** * Provides a confirmation form for cancelling user account. @@ -50,14 +48,10 @@ class UserCancelForm extends EntityNGConfirmFormBase implements EntityController /** * Constructs an EntityFormController object. * - * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler - * The module handler service. * @param \Drupal\Core\Config\ConfigFactory $config_factory * The config factory. */ - public function __construct(ModuleHandlerInterface $module_handler, ConfigFactory $config_factory) { - parent::__construct($module_handler); - + public function __construct(ConfigFactory $config_factory) { $this->configFactory = $config_factory; } @@ -66,7 +60,6 @@ public function __construct(ModuleHandlerInterface $module_handler, ConfigFactor */ public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) { return new static( - $container->get('module_handler'), $container->get('config.factory') ); } @@ -76,9 +69,9 @@ public static function createInstance(ContainerInterface $container, $entity_typ */ public function getQuestion() { if ($this->entity->id() == $this->user->id()) { - return t('Are you sure you want to cancel your account?'); + return $this->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())); + return $this->t('Are you sure you want to cancel the account %name?', array('%name' => $this->entity->label())); } /** @@ -95,35 +88,35 @@ public function getDescription() { $description = ''; $default_method = $this->configFactory->get('user.settings')->get('cancel_method'); if ($this->user->hasPermission('administer users') || $this->user->hasPermission('select account cancellation method')) { - $description = t('Select the method to cancel the account above.'); + $description = $this->t('Select the method to cancel the account above.'); } // Options supplied via user_cancel_methods() can have a custom // #confirm_description property for the confirmation form description. elseif (isset($this->cancelMethods[$default_method]['#confirm_description'])) { $description = $this->cancelMethods[$default_method]['#confirm_description']; } - return $description . ' ' . t('This action cannot be undone.'); + return $description . ' ' . $this->t('This action cannot be undone.'); } /** * {@inheritdoc} */ public function getConfirmText() { - return t('Cancel account'); + return $this->t('Cancel account'); } /** * {@inheritdoc} */ - public function buildForm(array $form, array &$form_state, Request $request = NULL) { + public function buildForm(array $form, array &$form_state) { $this->cancelMethods = user_cancel_methods(); - $this->user = $request->attributes->get('_account'); + $this->user = $this->getCurrentUser(); // Display account cancellation method selection, if allowed. $admin_access = $this->user->hasPermission('administer users'); $form['user_cancel_method'] = array( '#type' => 'radios', - '#title' => ($this->entity->id() == $this->user->id() ? t('When cancelling your account') : t('When cancelling the account')), + '#title' => ($this->entity->id() == $this->user->id() ? $this->t('When cancelling your account') : $this->t('When cancelling the account')), '#access' => $admin_access || $this->user->hasPermission('select account cancellation method'), ); $form['user_cancel_method'] += $this->cancelMethods; @@ -134,24 +127,24 @@ public function buildForm(array $form, array &$form_state, Request $request = NU $override_access = $admin_access && ($this->entity->id() != $this->user->id()); $form['user_cancel_confirm'] = array( '#type' => 'checkbox', - '#title' => t('Require e-mail confirmation to cancel account.'), + '#title' => $this->t('Require e-mail confirmation to cancel account.'), '#default_value' => ($override_access ? FALSE : TRUE), '#access' => $override_access, - '#description' => t('When enabled, the user must confirm the account cancellation via e-mail.'), + '#description' => $this->t('When enabled, the user must confirm the account cancellation via e-mail.'), ); // Also allow to send account canceled notification mail, if enabled. $default_notify = $this->configFactory->get('user.settings')->get('notify.status_canceled'); $form['user_cancel_notify'] = array( '#type' => 'checkbox', - '#title' => t('Notify user when account is canceled.'), + '#title' => $this->t('Notify user when account is canceled.'), '#default_value' => ($override_access ? FALSE : $default_notify), '#access' => $override_access && $default_notify, - '#description' => t('When enabled, the user will receive an e-mail notification after the account has been canceled.'), + '#description' => $this->t('When enabled, the user will receive an e-mail notification after the account has been canceled.'), ); // Always provide entity id in the same form key as in the entity edit form. $form['uid'] = array('#type' => 'value', '#value' => $this->entity->id()); - return parent::buildForm($form, $form_state, $request); + return parent::buildForm($form, $form_state); } /** @@ -173,7 +166,7 @@ public function submit(array $form, array &$form_state) { $this->entity->user_cancel_notify = $form_state['values']['user_cancel_notify']; $this->entity->save(); _user_mail_notify('cancel_confirm', $this->entity); - drupal_set_message(t('A confirmation request to cancel your account has been sent to your e-mail address.')); + drupal_set_message($this->t('A confirmation request to cancel your account has been sent to your e-mail address.')); watchdog('user', 'Sent account cancellation request to %name %email.', array('%name' => $this->entity->label(), '%email' => '<' . $this->entity->getEmail() . '>'), WATCHDOG_NOTICE); $form_state['redirect'] = 'user/' . $this->entity->id(); diff --git a/core/modules/user/lib/Drupal/user/Form/UserMultipleCancelConfirm.php b/core/modules/user/lib/Drupal/user/Form/UserMultipleCancelConfirm.php index 7ad5f3e..e03e860 100644 --- a/core/modules/user/lib/Drupal/user/Form/UserMultipleCancelConfirm.php +++ b/core/modules/user/lib/Drupal/user/Form/UserMultipleCancelConfirm.php @@ -12,11 +12,11 @@ use Drupal\Core\Controller\ControllerInterface; use Drupal\Core\Entity\EntityManager; use Drupal\Core\Form\ConfirmFormBase; +use Drupal\Core\Routing\UrlGeneratorInterface; use Drupal\user\TempStoreFactory; use Drupal\user\UserStorageControllerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RedirectResponse; -use Symfony\Component\HttpFoundation\Request; /** * Provides a confirmation form for cancelling user account. @@ -52,11 +52,11 @@ class UserMultipleCancelConfirm extends ConfirmFormBase implements ControllerInt protected $entityManager; /** - * The request object. + * The url generator service. * - * @var \Symfony\Component\HttpFoundation\Request + * @var \Drupal\Core\Routing\UrlGeneratorInterface */ - protected $request; + protected $urlGenerator; /** * Constructs a new UserMultipleCancelConfirm. @@ -69,12 +69,15 @@ class UserMultipleCancelConfirm extends ConfirmFormBase implements ControllerInt * The user storage controller. * @param \Drupal\Core\Entity\EntityManager $entity_manager * The entity manager. + * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator + * The url generator service. */ - public function __construct(TempStoreFactory $temp_store_factory, ConfigFactory $config_factory, UserStorageControllerInterface $user_storage, EntityManager $entity_manager) { + public function __construct(TempStoreFactory $temp_store_factory, ConfigFactory $config_factory, UserStorageControllerInterface $user_storage, EntityManager $entity_manager, UrlGeneratorInterface $url_generator) { $this->tempStoreFactory = $temp_store_factory; $this->configFactory = $config_factory; $this->userStorage = $user_storage; $this->entityManager = $entity_manager; + $this->urlGenerator = $url_generator; } /** @@ -85,7 +88,8 @@ public static function create(ContainerInterface $container) { $container->get('user.tempstore'), $container->get('config.factory'), $container->get('plugin.manager.entity')->getStorageController('user'), - $container->get('plugin.manager.entity') + $container->get('plugin.manager.entity'), + $container->get('url_generator') ); } @@ -100,7 +104,7 @@ public function getFormID() { * {@inheritdoc} */ public function getQuestion() { - return t('Are you sure you want to cancel these user accounts?'); + return $this->t('Are you sure you want to cancel these user accounts?'); } /** @@ -114,20 +118,19 @@ public function getCancelPath() { * {@inheritdoc} */ public function getConfirmText() { - return t('Cancel accounts'); + return $this->t('Cancel accounts'); } /** * {@inheritdoc} */ - public function buildForm(array $form, array &$form_state, Request $request = NULL) { - $this->request = $request; + public function buildForm(array $form, array &$form_state) { // Retrieve the accounts to be canceled from the temp store. $accounts = $this->tempStoreFactory ->get('user_user_operations_cancel') - ->get($request->attributes->get('_account')->id()); + ->get($this->getCurrentUser()->id()); if (!$accounts) { - return new RedirectResponse(url('admin/people', array('absolute' => TRUE))); + return new RedirectResponse($this->urlGenerator->generateFromPath('admin/people', array('absolute' => TRUE))); } $form['accounts'] = array('#prefix' => '', '#tree' => TRUE); @@ -147,11 +150,11 @@ public function buildForm(array $form, array &$form_state, Request $request = NU // Output a notice that user 1 cannot be canceled. if (isset($accounts[1])) { $redirect = (count($accounts) == 1); - $message = t('The user account %name cannot be canceled.', array('%name' => $accounts[1]->label())); + $message = $this->t('The user account %name cannot be canceled.', array('%name' => $accounts[1]->label())); drupal_set_message($message, $redirect ? 'error' : 'warning'); // If only user 1 was selected, redirect to the overview. if ($redirect) { - return new RedirectResponse(url('admin/people', array('absolute' => TRUE))); + return new RedirectResponse($this->urlGenerator->generateFromPath('admin/people', array('absolute' => TRUE))); } } @@ -159,7 +162,7 @@ public function buildForm(array $form, array &$form_state, Request $request = NU $form['user_cancel_method'] = array( '#type' => 'radios', - '#title' => t('When cancelling these accounts'), + '#title' => $this->t('When cancelling these accounts'), ); $form['user_cancel_method'] += user_cancel_methods(); @@ -167,27 +170,27 @@ public function buildForm(array $form, array &$form_state, Request $request = NU // Allow to send the account cancellation confirmation mail. $form['user_cancel_confirm'] = array( '#type' => 'checkbox', - '#title' => t('Require e-mail confirmation to cancel account.'), + '#title' => $this->t('Require e-mail confirmation to cancel account.'), '#default_value' => FALSE, - '#description' => t('When enabled, the user must confirm the account cancellation via e-mail.'), + '#description' => $this->t('When enabled, the user must confirm the account cancellation via e-mail.'), ); // Also allow to send account canceled notification mail, if enabled. $form['user_cancel_notify'] = array( '#type' => 'checkbox', - '#title' => t('Notify user when account is canceled.'), + '#title' => $this->t('Notify user when account is canceled.'), '#default_value' => FALSE, '#access' => $this->configFactory->get('user.settings')->get('notify.status_canceled'), - '#description' => t('When enabled, the user will receive an e-mail notification after the account has been canceled.'), + '#description' => $this->t('When enabled, the user will receive an e-mail notification after the account has been canceled.'), ); - return parent::buildForm($form, $form_state, $request); + return parent::buildForm($form, $form_state); } /** * {@inheritdoc} */ public function submitForm(array &$form, array &$form_state) { - $current_user_id = $this->request->attributes->get('_account')->id(); + $current_user_id = $this->getCurrentUser()->id(); // Clear out the accounts from the temp store. $this->tempStoreFactory->get('user_user_operations_cancel')->delete($current_user_id); diff --git a/core/modules/user/user.module b/core/modules/user/user.module index de53696..99b507d 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -919,7 +919,6 @@ function user_menu() { 'type' => MENU_DEFAULT_LOCAL_TASK, ); $items['user/%user/cancel'] = array( - 'title' => 'Cancel account', 'route_name' => 'user_cancel_confirm', ); $items['user/%user/cancel/confirm/%/%'] = array( diff --git a/core/modules/user/user.routing.yml b/core/modules/user/user.routing.yml index d5e4722..142d053 100644 --- a/core/modules/user/user.routing.yml +++ b/core/modules/user/user.routing.yml @@ -113,6 +113,7 @@ user_login: user_cancel_confirm: pattern: '/user/{user}/cancel' defaults: + _title: 'Cancel account' _entity_form: 'user.cancel' requirements: _entity_access: 'user.delete'