Commit 02a7ac8f authored by alexpott's avatar alexpott

Issue #2071481 by tim.plunkett: Modernize user.module forms.

parent 9e01ce3c
......@@ -36,9 +36,9 @@ public function form(array $form, array &$form_state) {
// Only show name field on registration form or user can change own username.
$form['account']['name'] = array(
'#type' => 'textfield',
'#title' => t('Username'),
'#title' => $this->t('Username'),
'#maxlength' => USERNAME_MAX_LENGTH,
'#description' => t('Spaces are allowed; punctuation is not allowed except for periods, hyphens, apostrophes, and underscores.'),
'#description' => $this->t('Spaces are allowed; punctuation is not allowed except for periods, hyphens, apostrophes, and underscores.'),
'#required' => TRUE,
'#attributes' => array('class' => array('username'), 'autocorrect' => 'off', 'autocomplete' => 'off', 'autocapitalize' => 'off',
'spellcheck' => 'false'),
......@@ -52,8 +52,8 @@ public function form(array $form, array &$form_state) {
// This allows users without e-mail address to be edited and deleted.
$form['account']['mail'] = array(
'#type' => 'email',
'#title' => t('E-mail address'),
'#description' => t('A valid e-mail address. All e-mails from the system will be sent to this address. The e-mail address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by e-mail.'),
'#title' => $this->t('E-mail address'),
'#description' => $this->t('A valid e-mail address. All e-mails from the system will be sent to this address. The e-mail address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by e-mail.'),
'#required' => !(!$account->getEmail() && user_access('administer users')),
'#default_value' => (!$register ? $account->getEmail() : ''),
'#attributes' => array('autocomplete' => 'off'),
......@@ -65,7 +65,7 @@ public function form(array $form, array &$form_state) {
$form['account']['pass'] = array(
'#type' => 'password_confirm',
'#size' => 25,
'#description' => t('To change the current user password, enter the new password in both fields.'),
'#description' => $this->t('To change the current user password, enter the new password in both fields.'),
);
// To skip the current password field, the user must have logged in via a
......@@ -79,9 +79,9 @@ public function form(array $form, array &$form_state) {
// password if they logged in via a one-time login link.
if (!$pass_reset) {
$protected_values['mail'] = $form['account']['mail']['#title'];
$protected_values['pass'] = t('Password');
$request_new = l(t('Request new password'), 'user/password', array('attributes' => array('title' => t('Request new password via e-mail.'))));
$current_pass_description = t('Required if you want to change the %mail or %pass below. !request_new.', array('%mail' => $protected_values['mail'], '%pass' => $protected_values['pass'], '!request_new' => $request_new));
$protected_values['pass'] = $this->t('Password');
$request_new = l($this->t('Request new password'), 'user/password', array('attributes' => array('title' => $this->t('Request new password via e-mail.'))));
$current_pass_description = $this->t('Required if you want to change the %mail or %pass below. !request_new.', array('%mail' => $protected_values['mail'], '%pass' => $protected_values['pass'], '!request_new' => $request_new));
}
// The user must enter their current password to change to a new one.
......@@ -93,7 +93,7 @@ public function form(array $form, array &$form_state) {
$form['account']['current_pass'] = array(
'#type' => 'password',
'#title' => t('Current password'),
'#title' => $this->t('Current password'),
'#size' => 25,
'#access' => !empty($protected_values),
'#description' => $current_pass_description,
......@@ -112,7 +112,7 @@ public function form(array $form, array &$form_state) {
$form['account']['pass'] = array(
'#type' => 'password_confirm',
'#size' => 25,
'#description' => t('Provide a password for the new account in both fields.'),
'#description' => $this->t('Provide a password for the new account in both fields.'),
'#required' => TRUE,
);
}
......@@ -126,9 +126,9 @@ public function form(array $form, array &$form_state) {
$form['account']['status'] = array(
'#type' => 'radios',
'#title' => t('Status'),
'#title' => $this->t('Status'),
'#default_value' => $status,
'#options' => array(t('Blocked'), t('Active')),
'#options' => array($this->t('Blocked'), $this->t('Active')),
'#access' => $admin,
);
......@@ -148,7 +148,7 @@ public function form(array $form, array &$form_state) {
$form['account']['roles'] = array(
'#type' => 'checkboxes',
'#title' => t('Roles'),
'#title' => $this->t('Roles'),
'#default_value' => (!$register ? $account->getRoles() : array()),
'#options' => $roles,
'#access' => $roles && user_access('administer permissions'),
......@@ -157,23 +157,23 @@ public function form(array $form, array &$form_state) {
$form['account']['notify'] = array(
'#type' => 'checkbox',
'#title' => t('Notify user of new account'),
'#title' => $this->t('Notify user of new account'),
'#access' => $register && $admin,
);
// Signature.
$form['signature_settings'] = array(
'#type' => 'details',
'#title' => t('Signature settings'),
'#title' => $this->t('Signature settings'),
'#weight' => 1,
'#access' => (!$register && $config->get('signatures')),
);
$form['signature_settings']['signature'] = array(
'#type' => 'text_format',
'#title' => t('Signature'),
'#title' => $this->t('Signature'),
'#default_value' => $account->getSignature(),
'#description' => t('Your signature will be publicly displayed at the end of your comments.'),
'#description' => $this->t('Your signature will be publicly displayed at the end of your comments.'),
'#format' => $account->getSignatureFormat(),
);
......@@ -186,7 +186,7 @@ public function form(array $form, array &$form_state) {
$interface_language_is_default = language_negotiation_method_get_first(Language::TYPE_INTERFACE) != LANGUAGE_NEGOTIATION_SELECTED;
$form['language'] = array(
'#type' => language_multilingual() ? 'details' : 'container',
'#title' => t('Language settings'),
'#title' => $this->t('Language settings'),
// Display language selector when either creating a user on the admin
// interface or editing a user account.
'#access' => !$register || user_access('administer users'),
......@@ -194,15 +194,15 @@ public function form(array $form, array &$form_state) {
$form['language']['preferred_langcode'] = array(
'#type' => 'language_select',
'#title' => t('Site language'),
'#title' => $this->t('Site language'),
'#languages' => Language::STATE_CONFIGURABLE,
'#default_value' => $user_preferred_langcode,
'#description' => $interface_language_is_default ? t("This account's preferred language for e-mails and site presentation.") : t("This account's preferred language for e-mails."),
'#description' => $interface_language_is_default ? $this->t("This account's preferred language for e-mails and site presentation.") : $this->t("This account's preferred language for e-mails."),
);
$form['language']['preferred_admin_langcode'] = array(
'#type' => 'language_select',
'#title' => t('Administration pages language'),
'#title' => $this->t('Administration pages language'),
'#languages' => Language::STATE_CONFIGURABLE,
'#default_value' => $user_preferred_admin_langcode,
'#access' => user_access('access administration pages', $account),
......@@ -267,7 +267,7 @@ public function validate(array $form, array &$form_state) {
->fetchField();
if ($name_taken) {
form_set_error('name', t('The name %name is already taken.', array('%name' => $form_state['values']['name'])));
form_set_error('name', $this->t('The name %name is already taken.', array('%name' => $form_state['values']['name'])));
}
}
}
......@@ -286,10 +286,10 @@ public function validate(array $form, array &$form_state) {
if ($mail_taken) {
// Format error message dependent on whether the user is logged in or not.
if ($GLOBALS['user']->isAuthenticated()) {
form_set_error('mail', t('The e-mail address %email is already taken.', array('%email' => $mail)));
form_set_error('mail', $this->t('The e-mail address %email is already taken.', array('%email' => $mail)));
}
else {
form_set_error('mail', t('The e-mail address %email is already registered. <a href="@password">Have you forgotten your password?</a>', array('%email' => $mail, '@password' => url('user/password'))));
form_set_error('mail', $this->t('The e-mail address %email is already registered. <a href="@password">Have you forgotten your password?</a>', array('%email' => $mail, '@password' => url('user/password'))));
}
}
}
......@@ -304,8 +304,9 @@ public function validate(array $form, array &$form_state) {
$user_schema = drupal_get_schema('users');
if (drupal_strlen($form_state['values']['signature']) > $user_schema['fields']['signature']['length']) {
form_set_error('signature', t('The signature is too long: it must be %max characters or less.', array('%max' => $user_schema['fields']['signature']['length'])));
form_set_error('signature', $this->t('The signature is too long: it must be %max characters or less.', array('%max' => $user_schema['fields']['signature']['length'])));
}
}
}
}
......@@ -8,18 +8,15 @@
namespace Drupal\user\Form;
use Drupal\Core\Config\ConfigFactory;
use Drupal\Core\Controller\ControllerInterface;
use Drupal\Core\Database\Connection;
use Drupal\Core\Flood\FloodInterface;
use Drupal\Core\Form\FormInterface;
use Drupal\Core\Form\FormBase;
use Drupal\user\UserStorageControllerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Provides a user login form.
*/
class UserLoginForm implements FormInterface, ControllerInterface {
class UserLoginForm extends FormBase {
/**
* The config factory.
......@@ -28,13 +25,6 @@ class UserLoginForm implements FormInterface, ControllerInterface {
*/
protected $configFactory;
/**
* The request object.
*
* @var \Symfony\Component\HttpFoundation\Request
*/
protected $request;
/**
* The flood service.
*
......@@ -47,7 +37,7 @@ class UserLoginForm implements FormInterface, ControllerInterface {
*
* @var \Drupal\user\UserStorageControllerInterface
*/
protected $storageController;
protected $userStorage;
/**
* Constructs a new UserLoginForm.
......@@ -56,13 +46,13 @@ class UserLoginForm implements FormInterface, ControllerInterface {
* The config factory.
* @param \Drupal\Core\Flood\FloodInterface $flood
* The flood service.
* @param \Drupal\user\UserStorageControllerInterface $storage_controller
* @param \Drupal\user\UserStorageControllerInterface $user_storage
* The user storage controller.
*/
public function __construct(ConfigFactory $config_factory, FloodInterface $flood, UserStorageControllerInterface $storage_controller) {
public function __construct(ConfigFactory $config_factory, FloodInterface $flood, UserStorageControllerInterface $user_storage) {
$this->configFactory = $config_factory;
$this->flood = $flood;
$this->storageController = $storage_controller;
$this->userStorage = $user_storage;
}
/**
......@@ -86,15 +76,14 @@ public function getFormID() {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state, Request $request = NULL) {
$this->request = $request;
public function buildForm(array $form, array &$form_state) {
// Display login form:
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Username'),
'#title' => $this->t('Username'),
'#size' => 60,
'#maxlength' => USERNAME_MAX_LENGTH,
'#description' => t('Enter your @s username.', array('@s' => $this->configFactory->get('system.site')->get('name'))),
'#description' => $this->t('Enter your @s username.', array('@s' => $this->configFactory->get('system.site')->get('name'))),
'#required' => TRUE,
'#attributes' => array(
'autocorrect' => 'off',
......@@ -106,14 +95,14 @@ public function buildForm(array $form, array &$form_state, Request $request = NU
$form['pass'] = array(
'#type' => 'password',
'#title' => t('Password'),
'#title' => $this->t('Password'),
'#size' => 60,
'#description' => t('Enter the password that accompanies your username.'),
'#description' => $this->t('Enter the password that accompanies your username.'),
'#required' => TRUE,
);
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Log in'));
$form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Log in'));
$form['#validate'][] = array($this, 'validateName');
$form['#validate'][] = array($this, 'validateAuthentication');
......@@ -122,17 +111,11 @@ public function buildForm(array $form, array &$form_state, Request $request = NU
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, array &$form_state) {
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
$account = $this->storageController->load($form_state['uid']);
$account = $this->userStorage->load($form_state['uid']);
$form_state['redirect'] = 'user/' . $account->id();
user_login_finalize($account);
......@@ -144,7 +127,7 @@ public function submitForm(array &$form, array &$form_state) {
public function validateName(array &$form, array &$form_state) {
if (!empty($form_state['values']['name']) && user_is_blocked($form_state['values']['name'])) {
// Blocked in user administration.
form_set_error('name', t('The username %name has not been activated or is blocked.', array('%name' => $form_state['values']['name'])));
form_set_error('name', $this->t('The username %name has not been activated or is blocked.', array('%name' => $form_state['values']['name'])));
}
}
......@@ -166,7 +149,7 @@ public function validateAuthentication(array &$form, array &$form_state) {
$form_state['flood_control_triggered'] = 'ip';
return;
}
$accounts = $this->storageController->loadByProperties(array('name' => $form_state['values']['name'], 'status' => 1));
$accounts = $this->userStorage->loadByProperties(array('name' => $form_state['values']['name'], 'status' => 1));
$account = reset($accounts);
if ($account) {
if ($flood_config->get('uid_only')) {
......@@ -178,7 +161,7 @@ public function validateAuthentication(array &$form, array &$form_state) {
// The default identifier is a combination of uid and IP address. This
// is less secure but more resistant to denial-of-service attacks that
// could lock out all users with public user names.
$identifier = $account->id() . '-' . $this->request->getClientIP();
$identifier = $account->id() . '-' . $this->getRequest()->getClientIP();
}
$form_state['flood_control_user_identifier'] = $identifier;
......@@ -216,19 +199,19 @@ public function validateFinal(array &$form, array &$form_state) {
}
else {
// We did not find a uid, so the limit is IP-based.
form_set_error('name', t('Sorry, too many failed login attempts from your IP address. This IP address is temporarily blocked. Try again later or <a href="@url">request a new password</a>.', array('@url' => url('user/password'))));
form_set_error('name', $this->t('Sorry, too many failed login attempts from your IP address. This IP address is temporarily blocked. Try again later or <a href="@url">request a new password</a>.', array('@url' => url('user/password'))));
}
}
else {
form_set_error('name', t('Sorry, unrecognized username or password. <a href="@password">Have you forgotten your password?</a>', array('@password' => url('user/password', array('query' => array('name' => $form_state['values']['name']))))));
$accounts = $this->storageController->loadByProperties(array('name' => $form_state['values']['name']));
form_set_error('name', $this->t('Sorry, unrecognized username or password. <a href="@password">Have you forgotten your password?</a>', array('@password' => url('user/password', array('query' => array('name' => $form_state['values']['name']))))));
$accounts = $this->userStorage->loadByProperties(array('name' => $form_state['values']['name']));
if (!empty($accounts)) {
watchdog('user', 'Login attempt failed for %user.', array('%user' => $form_state['values']['name']));
}
else {
// If the username entered is not a valid user,
// only store the IP address.
watchdog('user', 'Login attempt failed from %ip.', array('%ip' => $this->request->getClientIp()));
watchdog('user', 'Login attempt failed from %ip.', array('%ip' => $this->getRequest()->getClientIp()));
}
}
}
......
......@@ -7,8 +7,7 @@
namespace Drupal\user\Form;
use Drupal\Core\Controller\ControllerInterface;
use Drupal\Core\Form\FormInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Language\Language;
use Drupal\Core\Language\LanguageManager;
use Drupal\user\UserStorageControllerInterface;
......@@ -18,7 +17,7 @@
/**
* Provides a user password reset form.
*/
class UserPasswordForm implements FormInterface, ControllerInterface {
class UserPasswordForm extends FormBase {
/**
* The user storage controller.
......@@ -70,12 +69,10 @@ public function getFormID() {
* @param \Symfony\Component\HttpFoundation\Request $request
* The request object.
*/
public function buildForm(array $form, array &$form_state, Request $request = NULL) {
global $user;
public function buildForm(array $form, array &$form_state) {
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Username or e-mail address'),
'#title' => $this->t('Username or e-mail address'),
'#size' => 60,
'#maxlength' => max(USERNAME_MAX_LENGTH, EMAIL_MAX_LENGTH),
'#required' => TRUE,
......@@ -87,20 +84,21 @@ public function buildForm(array $form, array &$form_state, Request $request = NU
),
);
// Allow logged in users to request this also.
$user = $this->getCurrentUser();
if ($user->isAuthenticated()) {
$form['name']['#type'] = 'value';
$form['name']['#value'] = $user->getEmail();
$form['mail'] = array(
'#prefix' => '<p>',
'#markup' => t('Password reset instructions will be mailed to %email. You must log out to use the password reset link in the e-mail.', array('%email' => $user->getEmail())),
'#markup' => $this->t('Password reset instructions will be mailed to %email. You must log out to use the password reset link in the e-mail.', array('%email' => $user->getEmail())),
'#suffix' => '</p>',
);
}
else {
$form['name']['#default_value'] = $request->query->get('name');
$form['name']['#default_value'] = $this->getRequest()->query->get('name');
}
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array('#type' => 'submit', '#value' => t('E-mail new password'));
$form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('E-mail new password'));
return $form;
}
......@@ -121,7 +119,7 @@ public function validateForm(array &$form, array &$form_state) {
form_set_value(array('#parents' => array('account')), $account, $form_state);
}
else {
form_set_error('name', t('Sorry, %name is not recognized as a username or an e-mail address.', array('%name' => $name)));
form_set_error('name', $this->t('Sorry, %name is not recognized as a username or an e-mail address.', array('%name' => $name)));
}
}
......@@ -136,7 +134,7 @@ public function submitForm(array &$form, array &$form_state) {
$mail = _user_mail_notify('password_reset', $account, $langcode);
if (!empty($mail)) {
watchdog('user', 'Password reset instructions mailed to %name at %email.', array('%name' => $account->getUsername(), '%email' => $account->getEmail()));
drupal_set_message(t('Further instructions have been sent to your e-mail address.'));
drupal_set_message($this->t('Further instructions have been sent to your e-mail address.'));
}
$form_state['redirect'] = 'user';
......
......@@ -9,16 +9,15 @@
use Drupal\Component\Utility\String;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Controller\ControllerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\FormInterface;
use Drupal\Core\Form\FormBase;
use Drupal\user\RoleStorageControllerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides the user permissions administration form.
*/
class UserPermissionsForm implements FormInterface, ControllerInterface {
class UserPermissionsForm extends FormBase {
/**
* The module handler.
......@@ -111,7 +110,7 @@ public function buildForm(array $form, array &$form_state) {
$form['permissions'] = array(
'#type' => 'table',
'#header' => array(t('Permission')),
'#header' => array($this->t('Permission')),
'#id' => 'permissions',
'#sticky' => TRUE,
);
......@@ -138,7 +137,7 @@ public function buildForm(array $form, array &$form_state) {
$perm_item += array(
'description' => '',
'restrict access' => FALSE,
'warning' => !empty($perm_item['restrict access']) ? t('Warning: Give to trusted roles only; this permission has security implications.') : '',
'warning' => !empty($perm_item['restrict access']) ? $this->t('Warning: Give to trusted roles only; this permission has security implications.') : '',
);
$options[$perm] = '';
$user_permission_description = array(
......@@ -173,19 +172,13 @@ public function buildForm(array $form, array &$form_state) {
}
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save permissions'));
$form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Save permissions'));
$form['#attached']['library'][] = array('user', 'drupal.user.permissions');
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, array &$form_state) {
}
/**
* {@inheritdoc}
*/
......@@ -194,7 +187,7 @@ function submitForm(array &$form, array &$form_state) {
user_role_change_permissions($role_name, $form_state['values'][$role_name]);
}
drupal_set_message(t('The changes have been saved.'));
drupal_set_message($this->t('The changes have been saved.'));
// Clear the cached pages and blocks.
Cache::invalidateTags(array('content' => TRUE));
......
......@@ -18,7 +18,7 @@ class UserRoleDelete extends EntityConfirmFormBase {
* {@inheritdoc}
*/
public function getQuestion() {
return t('Are you sure you want to delete the role %name?', array('%name' => $this->entity->label()));
return $this->t('Are you sure you want to delete the role %name?', array('%name' => $this->entity->label()));
}
/**
......@@ -32,7 +32,7 @@ public function getCancelPath() {
* {@inheritdoc}
*/
public function getConfirmText() {
return t('Delete');
return $this->t('Delete');
}
/**
......@@ -41,7 +41,7 @@ public function getConfirmText() {
public function submit(array $form, array &$form_state) {
$this->entity->delete();
watchdog('user', 'Role %name has been deleted.', array('%name' => $this->entity->label()));
drupal_set_message(t('Role %name has been deleted.', array('%name' => $this->entity->label())));
drupal_set_message($this->t('Role %name has been deleted.', array('%name' => $this->entity->label())));
$form_state['redirect'] = 'admin/people/roles';
}
......
......@@ -20,7 +20,7 @@ protected function actions(array $form, array &$form_state) {
$account = $this->entity;
$element['delete']['#type'] = 'submit';
$element['delete']['#value'] = t('Cancel account');
$element['delete']['#value'] = $this->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'));
......@@ -39,6 +39,7 @@ public function save(array $form, array &$form_state) {
// information:
cache_invalidate_tags(array('content' => TRUE));
drupal_set_message(t('The changes have been saved.'));
drupal_set_message($this->t('The changes have been saved.'));
}
}
......@@ -59,7 +59,7 @@ public function form(array $form, array &$form_state) {
*/
protected function actions(array $form, array &$form_state) {
$element = parent::actions($form, $form_state);
$element['submit']['#value'] = t('Create new account');
$element['submit']['#value'] = $this->t('Create new account');
return $element;
}
......@@ -101,7 +101,7 @@ public function save(array $form, array &$form_state) {
$form_state['user'] = $account;
$form_state['values']['uid'] = $account->id();
watchdog('user', 'New user: %name %email.', array('%name' => $form_state['values']['name'], '%email' => '<' . $form_state['values']['mail'] . '>'), WATCHDOG_NOTICE, l(t('edit'), 'user/' . $account->id() . '/edit'));
watchdog('user', 'New user: %name %email.', array('%name' => $form_state['values']['name'], '%email' => '<' . $form_state['values']['mail'] . '>'), WATCHDOG_NOTICE, l($this->t('edit'), 'user/' . $account->id() . '/edit'));
// Add plain text password into user account to generate mail tokens.
$account->password = $pass;
......@@ -109,28 +109,28 @@ public function save(array $form, array &$form_state) {
// New administrative account without notification.
$uri = $account->uri();
if ($admin && !$notify) {
drupal_set_message(t('Created a new user account for <a href="@url">%name</a>. No e-mail has been sent.', array('@url' => url($uri['path'], $uri['options']), '%name' => $account->getUsername())));
drupal_set_message($this->t('Created a new user account for <a href="@url">%name</a>. No e-mail has been sent.', array('@url' => url($uri['path'], $uri['options']), '%name' => $account->getUsername())));
}
// No e-mail verification required; log in user immediately.
elseif (!$admin && !\Drupal::config('user.settings')->get('verify_mail') && $account->isActive()) {
_user_mail_notify('register_no_approval_required', $account);
user_login_finalize($account);
drupal_set_message(t('Registration successful. You are now logged in.'));
drupal_set_message($this->t('Registration successful. You are now logged in.'));
$form_state['redirect'] = '';
}
// No administrator approval required.
elseif ($account->isActive() || $notify) {
if (!$account->getEmail() && $notify) {
drupal_set_message(t('The new user <a href="@url">%name</a> was created without an email address, so no welcome message was sent.', array('@url' => url($uri['path'], $uri['options']), '%name' => $account->getUsername())));
drupal_set_message($this->t('The new user <a href="@url">%name</a> was created without an email address, so no welcome message was sent.', array('@url' => url($uri['path'], $uri['options']), '%name' => $account->getUsername())));
}
else {
$op = $notify ? 'register_admin_created' : 'register_no_approval_required';
if (_user_mail_notify($op, $account)) {
if ($notify) {
drupal_set_message(t('A welcome message with further instructions has been e-mailed to the new user <a href="@url">%name</a>.', array('@url' => url($uri['path'], $uri['options']), '%name' => $account->getUsername())));
drupal_set_message($this->t('A welcome message with further instructions has been e-mailed to the new user <a href="@url">%name</a>.', array('@url' => url($uri['path'], $uri['options']), '%name' => $account->getUsername())));
}
else {
drupal_set_message(t('A welcome message with further instructions has been sent to your e-mail address.'));
drupal_set_message($this->t('A welcome message with further instructions has been sent to your e-mail address.'));
$form_state['redirect'] = '';
}
}
......@@ -139,7 +139,7 @@ public function save(array $form, array &$form_state) {
// Administrator approval required.
else {
_user_mail_notify('register_pending_approval', $account);
drupal_set_message(t('Thank you for applying for an account. Your account is currently pending approval by the site administrator.<br />In the meantime, a welcome message with further instructions has been sent to your e-mail address.'));
drupal_set_message($this->t('Thank you for applying for an account. Your account is currently pending approval by the site administrator.<br />In the meantime, a welcome message with further instructions has been sent to your e-mail address.'));
$form_state['redirect'] = '';
}
}
......
......@@ -22,12 +22,12 @@ public function form(array $form, array &$form_state) {
$entity = $this->entity;
$form['label'] = array(
'#type' => 'textfield',
'#title' => t('Role name'),
'#title' => $this->t('Role name'),
'#default_value' => $entity->label(),
'#size' => 30,
'#required' => TRUE,
'#maxlength' => 64,
'#description' => t('The name for this role. Example: "Moderator", "Editorial board", "Site architect".'),
'#description' => $this->t('The name for this role. Example: "Moderator", "Editorial board", "Site architect".'),
);
$form['id'] = array(
'#type' => 'machine_name',
......@@ -68,12 +68,12 @@ public function save(array $form, array &$form_state) {
$entity->set('label', trim($entity->label()));
$uri = $entity->uri();
if ($entity->save() == SAVED_UPDATED) {
drupal_set_message(t('Role %label has been updated.', array('%label' => $entity->label())));
watchdog('user', 'Role %label has been updated.', array('%label' => $entity->label()), WATCHDOG_NOTICE, l(t('Edit'), $uri['path']));
drupal_set_message($this->t('Role %label has been updated.', array('%label' => $entity->label())));
watchdog('user', 'Role %label has been updated.', array('%label' => $entity->label()), WATCHDOG_NOTICE, l($this->t('Edit'), $uri['path']));
}
else {
drupal_set_message(t('Role %label has been added.', array('%label' => $entity->label())));
watchdog('user', 'Role %label has been added.', array('%label' => $entity->label()), WATCHDOG_NOTICE, l(t('Edit'), $uri['path']));
drupal_set_message($this->t('Role %label has been added.', array('%label' => $entity->label())));
watchdog('user', 'Role %label has been added.', array('%label' => $entity->label()), WATCHDOG_NOTICE, l($this->t('Edit'), $uri['path']));
}
$form_state['redirect'] = 'admin/people/roles';
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment