diff --git a/core/modules/user/lib/Drupal/user/ProfileFormController.php b/core/modules/user/lib/Drupal/user/ProfileFormController.php index c10c226..ae65e0e 100644 --- a/core/modules/user/lib/Drupal/user/ProfileFormController.php +++ b/core/modules/user/lib/Drupal/user/ProfileFormController.php @@ -7,22 +7,47 @@ namespace Drupal\user; +use Symfony\Component\HttpFoundation\Request; + /** * Form controller for the profile forms. */ class ProfileFormController extends AccountFormController { /** + * {@inheritdoc} + */ + public function buildForm(array $form, array &$form_state, Request $request = NULL) { + $this->request = $request; + return parent::buildForm($form, $form_state); + } + + /** * Overrides Drupal\Core\Entity\EntityFormController::actions(). */ protected function actions(array $form, array &$form_state) { $element = parent::actions($form, $form_state); - $account = $this->entity; + + // Get the user accessing the form. + $user = $request->attributes->get('_account'); + + // Get the account being edited. + $account = $this->getEntity(); + + // Initial checks used in controlling access to the "Cancel account" and + // "Re-send welcome message" buttons. + $normal_user = $account->id() > 1; + $cancel_own = ($account->id() == $user->id()) && $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 || $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() && $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'); + } +}