diff --git a/core/modules/user/lib/Drupal/user/ProfileFormController.php b/core/modules/user/lib/Drupal/user/ProfileFormController.php index c10c226..f8efd4c 100644 --- a/core/modules/user/lib/Drupal/user/ProfileFormController.php +++ b/core/modules/user/lib/Drupal/user/ProfileFormController.php @@ -19,10 +19,24 @@ protected function actions(array $form, array &$form_state) { $element = parent::actions($form, $form_state); $account = $this->entity; + // @TODO This needs to be passed via dependency injection, probably by + // implementing createInstance()... which is not called for this form, + // because it doesn't implement Drupal\Core\Entity\EntityControllerInterface + // @see EntityManger::getFormController() + $this->user = $GLOBALS['user']; + + $normal_user = $account->id() > 1; + $cancel_own = ($account->id() == $this->user->id()) && $this->user->hasPermission('cancel account'); + $element['delete']['#type'] = 'submit'; $element['delete']['#value'] = t('Cancel account'); $element['delete']['#submit'] = array('user_edit_cancel_submit'); - $element['delete']['#access'] = $account->id() > 1 && (($account->id() == $GLOBALS['user']->id() && user_access('cancel account')) || user_access('administer users')); + $element['delete']['#access'] = $normal_user && ($cancel_own || $this->user->hasPermission('administer users')); + + $element['resend']['#type'] = 'submit'; + $element['resend']['#value'] = t('Re-send welcome message'); + $element['resend']['#submit'] = array('user_edit_resend_submit'); + $element['resend']['#access'] = $normal_user && $account->getEmail() && $this->user->hasPermission('administer users'); return $element; } diff --git a/core/modules/user/user.pages.inc b/core/modules/user/user.pages.inc index 2aa9b88..04e93ac 100644 --- a/core/modules/user/user.pages.inc +++ b/core/modules/user/user.pages.inc @@ -324,3 +324,42 @@ function user_cancel_confirm($account, $timestamp = 0, $hashed_pass = '') { } throw new AccessDeniedHttpException(); } + +/** + * Submit function for the 'Re-send welcome message' button on the user edit form. + * + * @TODO Should this live in ProfileFormController::save()? + */ +function user_edit_resend_submit($form, &$form_state) { + global $language; + + // Get the user entity from the form. + $account = $form_state['controller']->getEntity(); + + // Determine the user approval method. + $config = Drupal::getContainer()->get('config.factory')->get('user.settings'); + switch ($config->get('register')) { + case USER_REGISTER_ADMINISTRATORS_ONLY: + $op = 'register_admin_created'; + break; + case USER_REGISTER_VISITORS: + $op = 'register_no_approval_required'; + break; + case USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL: + default: + $op = 'register_pending_approval'; + } + + // Notify the user via email. + $mail = _user_mail_notify($op, $account, $language); + + // Log the mail. + if (!empty($mail)) { + watchdog('user', 'Welcome message has been re-sent to %name at %email.', array('%name' => $account->getUsername(), '%email' => $account->getEmail())); + drupal_set_message(t('Welcome message has been re-sent to %name at %email', array('%name' => $account->getUsername(), '%email' => $account->getEmail()))); + } + else { + watchdog('user', 'There was an error re-sending welcome message to %name at %email', array('%name' => $account->getUsername(), '%email' => $account->getEmail())); + drupal_set_message(t('There was an error re-sending welcome message to %name at %email', array('%name' => $account->getUsername(), '%email' => $account->getEmail())), 'error'); + } +}