Update core 8.3.0
This commit is contained in:
parent
da7a7918f8
commit
cd7a898e66
6144 changed files with 132297 additions and 87747 deletions
|
@ -617,6 +617,54 @@ display:
|
|||
name: name
|
||||
mail: mail
|
||||
plugin_id: combine
|
||||
status:
|
||||
id: status
|
||||
table: users_field_data
|
||||
field: status
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
operator: '='
|
||||
value: '1'
|
||||
group: 1
|
||||
exposed: true
|
||||
expose:
|
||||
operator_id: ''
|
||||
label: ''
|
||||
description: ''
|
||||
use_operator: false
|
||||
operator: status_op
|
||||
identifier: status
|
||||
required: false
|
||||
remember: false
|
||||
multiple: false
|
||||
remember_roles:
|
||||
authenticated: authenticated
|
||||
anonymous: '0'
|
||||
administrator: '0'
|
||||
is_grouped: true
|
||||
group_info:
|
||||
label: Status
|
||||
description: ''
|
||||
identifier: status
|
||||
optional: true
|
||||
widget: select
|
||||
multiple: false
|
||||
remember: false
|
||||
default_group: All
|
||||
default_group_multiple: { }
|
||||
group_items:
|
||||
1:
|
||||
title: Active
|
||||
operator: '='
|
||||
value: '1'
|
||||
2:
|
||||
title: Blocked
|
||||
operator: '='
|
||||
value: '0'
|
||||
plugin_id: boolean
|
||||
entity_type: user
|
||||
entity_field: status
|
||||
roles_target_id:
|
||||
id: roles_target_id
|
||||
table: user__roles
|
||||
|
@ -697,54 +745,6 @@ display:
|
|||
group_items: { }
|
||||
reduce_duplicates: false
|
||||
plugin_id: user_permissions
|
||||
status:
|
||||
id: status
|
||||
table: users_field_data
|
||||
field: status
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
operator: '='
|
||||
value: '1'
|
||||
group: 1
|
||||
exposed: true
|
||||
expose:
|
||||
operator_id: ''
|
||||
label: ''
|
||||
description: ''
|
||||
use_operator: false
|
||||
operator: status_op
|
||||
identifier: status
|
||||
required: false
|
||||
remember: false
|
||||
multiple: false
|
||||
remember_roles:
|
||||
authenticated: authenticated
|
||||
anonymous: '0'
|
||||
administrator: '0'
|
||||
is_grouped: true
|
||||
group_info:
|
||||
label: Status
|
||||
description: ''
|
||||
identifier: status
|
||||
optional: true
|
||||
widget: select
|
||||
multiple: false
|
||||
remember: false
|
||||
default_group: All
|
||||
default_group_multiple: { }
|
||||
group_items:
|
||||
1:
|
||||
title: Active
|
||||
operator: '='
|
||||
value: '1'
|
||||
2:
|
||||
title: Blocked
|
||||
operator: '='
|
||||
value: '0'
|
||||
plugin_id: boolean
|
||||
entity_type: user
|
||||
entity_field: status
|
||||
default_langcode:
|
||||
id: default_langcode
|
||||
table: users_field_data
|
||||
|
|
|
@ -11,9 +11,6 @@ source:
|
|||
# table are specified, and must end with a /.
|
||||
source_base_path: ''
|
||||
process:
|
||||
# If you are using both this migration and d6_file in a custom migration
|
||||
# and executing migrations incrementally, it is recommended that you
|
||||
# remove the fid mapping from d6_file to avoid potential ID conflicts.
|
||||
filename: filename
|
||||
uid: uid
|
||||
source_full_path:
|
||||
|
|
|
@ -2,11 +2,12 @@
|
|||
|
||||
namespace Drupal\user;
|
||||
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Component\Utility\Crypt;
|
||||
use Drupal\Core\Entity\ContentEntityForm;
|
||||
use Drupal\Core\Entity\EntityConstraintViolationListInterface;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Entity\Query\QueryFactory;
|
||||
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\Language\LanguageManagerInterface;
|
||||
|
@ -27,13 +28,6 @@ abstract class AccountForm extends ContentEntityForm {
|
|||
*/
|
||||
protected $languageManager;
|
||||
|
||||
/**
|
||||
* The entity query factory service.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\Query\QueryFactory
|
||||
*/
|
||||
protected $entityQuery;
|
||||
|
||||
/**
|
||||
* Constructs a new EntityForm object.
|
||||
*
|
||||
|
@ -41,13 +35,14 @@ abstract class AccountForm extends ContentEntityForm {
|
|||
* The entity manager.
|
||||
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
|
||||
* The language manager.
|
||||
* @param \Drupal\Core\Entity\Query\QueryFactory $entity_query
|
||||
* The entity query factory.
|
||||
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
|
||||
* The entity type bundle service.
|
||||
* @param \Drupal\Component\Datetime\TimeInterface $time
|
||||
* The time service.
|
||||
*/
|
||||
public function __construct(EntityManagerInterface $entity_manager, LanguageManagerInterface $language_manager, QueryFactory $entity_query) {
|
||||
parent::__construct($entity_manager);
|
||||
public function __construct(EntityManagerInterface $entity_manager, LanguageManagerInterface $language_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, TimeInterface $time = NULL) {
|
||||
parent::__construct($entity_manager, $entity_type_bundle_info, $time);
|
||||
$this->languageManager = $language_manager;
|
||||
$this->entityQuery = $entity_query;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -57,7 +52,8 @@ abstract class AccountForm extends ContentEntityForm {
|
|||
return new static(
|
||||
$container->get('entity.manager'),
|
||||
$container->get('language_manager'),
|
||||
$container->get('entity.query')
|
||||
$container->get('entity_type.bundle.info'),
|
||||
$container->get('datetime.time')
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -76,48 +72,48 @@ abstract class AccountForm extends ContentEntityForm {
|
|||
$admin = $user->hasPermission('administer users');
|
||||
|
||||
// Account information.
|
||||
$form['account'] = array(
|
||||
$form['account'] = [
|
||||
'#type' => 'container',
|
||||
'#weight' => -10,
|
||||
);
|
||||
];
|
||||
|
||||
// The mail field is NOT required if account originally had no mail set
|
||||
// and the user performing the edit has 'administer users' permission.
|
||||
// This allows users without email address to be edited and deleted.
|
||||
// Also see \Drupal\user\Plugin\Validation\Constraint\UserMailRequired.
|
||||
$form['account']['mail'] = array(
|
||||
$form['account']['mail'] = [
|
||||
'#type' => 'email',
|
||||
'#title' => $this->t('Email address'),
|
||||
'#description' => $this->t('A valid email address. All emails from the system will be sent to this address. The email 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 email.'),
|
||||
'#required' => !(!$account->getEmail() && $user->hasPermission('administer users')),
|
||||
'#default_value' => (!$register ? $account->getEmail() : ''),
|
||||
);
|
||||
];
|
||||
|
||||
// Only show name field on registration form or user can change own username.
|
||||
$form['account']['name'] = array(
|
||||
$form['account']['name'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Username'),
|
||||
'#maxlength' => USERNAME_MAX_LENGTH,
|
||||
'#description' => $this->t("Several special characters are allowed, including space, period (.), hyphen (-), apostrophe ('), underscore (_), and the @ sign."),
|
||||
'#required' => TRUE,
|
||||
'#attributes' => array(
|
||||
'class' => array('username'),
|
||||
'#attributes' => [
|
||||
'class' => ['username'],
|
||||
'autocorrect' => 'off',
|
||||
'autocapitalize' => 'off',
|
||||
'spellcheck' => 'false',
|
||||
),
|
||||
'#default_value' => (!$register ? $account->getUsername() : ''),
|
||||
],
|
||||
'#default_value' => (!$register ? $account->getAccountName() : ''),
|
||||
'#access' => ($register || ($user->id() == $account->id() && $user->hasPermission('change own username')) || $admin),
|
||||
);
|
||||
];
|
||||
|
||||
// Display password field only for existing users or when user is allowed to
|
||||
// assign a password during registration.
|
||||
if (!$register) {
|
||||
$form['account']['pass'] = array(
|
||||
$form['account']['pass'] = [
|
||||
'#type' => 'password_confirm',
|
||||
'#size' => 25,
|
||||
'#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
|
||||
// one-time link and have the token in the URL. Store this in $form_state
|
||||
|
@ -130,7 +126,7 @@ abstract class AccountForm extends ContentEntityForm {
|
|||
|
||||
// The user must enter their current password to change to a new one.
|
||||
if ($user->id() == $account->id()) {
|
||||
$form['account']['current_pass'] = array(
|
||||
$form['account']['current_pass'] = [
|
||||
'#type' => 'password',
|
||||
'#title' => $this->t('Current password'),
|
||||
'#size' => 25,
|
||||
|
@ -139,34 +135,34 @@ abstract class AccountForm extends ContentEntityForm {
|
|||
// Do not let web browsers remember this password, since we are
|
||||
// trying to confirm that the person submitting the form actually
|
||||
// knows the current one.
|
||||
'#attributes' => array('autocomplete' => 'off'),
|
||||
);
|
||||
'#attributes' => ['autocomplete' => 'off'],
|
||||
];
|
||||
$form_state->set('user', $account);
|
||||
|
||||
// The user may only change their own password without their current
|
||||
// password if they logged in via a one-time login link.
|
||||
if (!$form_state->get('user_pass_reset')) {
|
||||
$form['account']['current_pass']['#description'] = $this->t('Required if you want to change the %mail or %pass below. <a href=":request_new_url" title="Send password reset instructions via email.">Reset your password</a>.', array(
|
||||
$form['account']['current_pass']['#description'] = $this->t('Required if you want to change the %mail or %pass below. <a href=":request_new_url" title="Send password reset instructions via email.">Reset your password</a>.', [
|
||||
'%mail' => $form['account']['mail']['#title'],
|
||||
'%pass' => $this->t('Password'),
|
||||
':request_new_url' => $this->url('user.pass'),
|
||||
));
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (!$config->get('verify_mail') || $admin) {
|
||||
$form['account']['pass'] = array(
|
||||
$form['account']['pass'] = [
|
||||
'#type' => 'password_confirm',
|
||||
'#size' => 25,
|
||||
'#description' => $this->t('Provide a password for the new account in both fields.'),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
// When not building the user registration form, prevent web browsers from
|
||||
// autofilling/prefilling the email, username, and password fields.
|
||||
if ($this->getOperation() != 'register') {
|
||||
foreach (array('mail', 'name', 'pass') as $key) {
|
||||
foreach (['mail', 'name', 'pass'] as $key) {
|
||||
if (isset($form['account'][$key])) {
|
||||
$form['account'][$key]['#attributes']['autocomplete'] = 'off';
|
||||
}
|
||||
|
@ -180,35 +176,35 @@ abstract class AccountForm extends ContentEntityForm {
|
|||
$status = $config->get('register') == USER_REGISTER_VISITORS ? 1 : 0;
|
||||
}
|
||||
|
||||
$form['account']['status'] = array(
|
||||
$form['account']['status'] = [
|
||||
'#type' => 'radios',
|
||||
'#title' => $this->t('Status'),
|
||||
'#default_value' => $status,
|
||||
'#options' => array($this->t('Blocked'), $this->t('Active')),
|
||||
'#options' => [$this->t('Blocked'), $this->t('Active')],
|
||||
'#access' => $admin,
|
||||
);
|
||||
];
|
||||
|
||||
$roles = array_map(array('\Drupal\Component\Utility\Html', 'escape'), user_role_names(TRUE));
|
||||
$roles = array_map(['\Drupal\Component\Utility\Html', 'escape'], user_role_names(TRUE));
|
||||
|
||||
$form['account']['roles'] = array(
|
||||
$form['account']['roles'] = [
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => $this->t('Roles'),
|
||||
'#default_value' => (!$register ? $account->getRoles() : array()),
|
||||
'#default_value' => (!$register ? $account->getRoles() : []),
|
||||
'#options' => $roles,
|
||||
'#access' => $roles && $user->hasPermission('administer permissions'),
|
||||
);
|
||||
];
|
||||
|
||||
// Special handling for the inevitable "Authenticated user" role.
|
||||
$form['account']['roles'][RoleInterface::AUTHENTICATED_ID] = array(
|
||||
$form['account']['roles'][RoleInterface::AUTHENTICATED_ID] = [
|
||||
'#default_value' => TRUE,
|
||||
'#disabled' => TRUE,
|
||||
);
|
||||
];
|
||||
|
||||
$form['account']['notify'] = array(
|
||||
$form['account']['notify'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Notify user of new account'),
|
||||
'#access' => $register && $admin,
|
||||
);
|
||||
];
|
||||
|
||||
$user_preferred_langcode = $register ? $language_interface->getId() : $account->getPreferredLangcode();
|
||||
|
||||
|
@ -220,16 +216,16 @@ abstract class AccountForm extends ContentEntityForm {
|
|||
$negotiator = $this->languageManager->getNegotiator();
|
||||
$user_language_added = $negotiator && $negotiator->isNegotiationMethodEnabled(LanguageNegotiationUser::METHOD_ID, LanguageInterface::TYPE_INTERFACE);
|
||||
}
|
||||
$form['language'] = array(
|
||||
$form['language'] = [
|
||||
'#type' => $this->languageManager->isMultilingual() ? 'details' : 'container',
|
||||
'#title' => $this->t('Language settings'),
|
||||
'#open' => TRUE,
|
||||
// Display language selector when either creating a user on the admin
|
||||
// interface or editing a user account.
|
||||
'#access' => !$register || $user->hasPermission('administer users'),
|
||||
);
|
||||
];
|
||||
|
||||
$form['language']['preferred_langcode'] = array(
|
||||
$form['language']['preferred_langcode'] = [
|
||||
'#type' => 'language_select',
|
||||
'#title' => $this->t('Site language'),
|
||||
'#languages' => LanguageInterface::STATE_CONFIGURABLE,
|
||||
|
@ -239,7 +235,7 @@ abstract class AccountForm extends ContentEntityForm {
|
|||
// language are synchronized. It can be removed if a different behavior is
|
||||
// desired.
|
||||
'#pre_render' => ['user_langcode' => [$this, 'alterPreferredLangcodeDescription']],
|
||||
);
|
||||
];
|
||||
|
||||
// Only show the account setting for Administration pages language to users
|
||||
// if one of the detection and selection methods uses it.
|
||||
|
@ -248,7 +244,7 @@ abstract class AccountForm extends ContentEntityForm {
|
|||
$negotiator = $this->languageManager->getNegotiator();
|
||||
$show_admin_language = $negotiator && $negotiator->isNegotiationMethodEnabled(LanguageNegotiationUserAdmin::METHOD_ID);
|
||||
}
|
||||
$form['language']['preferred_admin_langcode'] = array(
|
||||
$form['language']['preferred_admin_langcode'] = [
|
||||
'#type' => 'language_select',
|
||||
'#title' => $this->t('Administration pages language'),
|
||||
'#languages' => LanguageInterface::STATE_CONFIGURABLE,
|
||||
|
@ -256,7 +252,7 @@ abstract class AccountForm extends ContentEntityForm {
|
|||
'#access' => $show_admin_language,
|
||||
'#empty_option' => $this->t('- No preference -'),
|
||||
'#empty_value' => '',
|
||||
);
|
||||
];
|
||||
|
||||
// User entities contain both a langcode property (for identifying the
|
||||
// language of the entity data) and a preferred_langcode property (see
|
||||
|
@ -265,7 +261,7 @@ abstract class AccountForm extends ContentEntityForm {
|
|||
// language. This entity builder provides that synchronization. For
|
||||
// use-cases where this synchronization is not desired, a module can alter
|
||||
// or remove this item.
|
||||
$form['#entity_builders']['sync_user_langcode'] = [$this, 'syncUserLangcode'];
|
||||
$form['#entity_builders']['sync_user_langcode'] = '::syncUserLangcode';
|
||||
|
||||
return parent::form($form, $form_state, $account);
|
||||
}
|
||||
|
@ -321,7 +317,7 @@ abstract class AccountForm extends ContentEntityForm {
|
|||
$account = parent::buildEntity($form, $form_state);
|
||||
|
||||
// Translate the empty value '' of language selects to an unset field.
|
||||
foreach (array('preferred_langcode', 'preferred_admin_langcode') as $field_name) {
|
||||
foreach (['preferred_langcode', 'preferred_admin_langcode'] as $field_name) {
|
||||
if ($form_state->getValue($field_name) === '') {
|
||||
$account->$field_name = NULL;
|
||||
}
|
||||
|
@ -344,7 +340,7 @@ abstract class AccountForm extends ContentEntityForm {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getEditedFieldNames(FormStateInterface $form_state) {
|
||||
return array_merge(array(
|
||||
return array_merge([
|
||||
'name',
|
||||
'pass',
|
||||
'mail',
|
||||
|
@ -352,7 +348,7 @@ abstract class AccountForm extends ContentEntityForm {
|
|||
'langcode',
|
||||
'preferred_langcode',
|
||||
'preferred_admin_langcode'
|
||||
), parent::getEditedFieldNames($form_state));
|
||||
], parent::getEditedFieldNames($form_state));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -362,7 +358,7 @@ abstract class AccountForm extends ContentEntityForm {
|
|||
// Manually flag violations of fields not handled by the form display. This
|
||||
// is necessary as entity form displays only flag violations for fields
|
||||
// contained in the display.
|
||||
$field_names = array(
|
||||
$field_names = [
|
||||
'name',
|
||||
'pass',
|
||||
'mail',
|
||||
|
@ -370,7 +366,7 @@ abstract class AccountForm extends ContentEntityForm {
|
|||
'langcode',
|
||||
'preferred_langcode',
|
||||
'preferred_admin_langcode'
|
||||
);
|
||||
];
|
||||
foreach ($violations->getByFields($field_names) as $violation) {
|
||||
list($field_name) = explode('.', $violation->getPropertyPath(), 2);
|
||||
$form_state->setErrorByName($field_name, $violation->getMessage());
|
||||
|
|
|
@ -85,25 +85,25 @@ class AccountSettingsForm extends ConfigFormBase {
|
|||
$form['#attached']['library'][] = 'user/drupal.user.admin';
|
||||
|
||||
// Settings for anonymous users.
|
||||
$form['anonymous_settings'] = array(
|
||||
$form['anonymous_settings'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Anonymous users'),
|
||||
'#open' => TRUE,
|
||||
);
|
||||
$form['anonymous_settings']['anonymous'] = array(
|
||||
];
|
||||
$form['anonymous_settings']['anonymous'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Name'),
|
||||
'#default_value' => $config->get('anonymous'),
|
||||
'#description' => $this->t('The name used to indicate anonymous users.'),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
];
|
||||
|
||||
// Administrative role option.
|
||||
$form['admin_role'] = array(
|
||||
$form['admin_role'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Administrator role'),
|
||||
'#open' => TRUE,
|
||||
);
|
||||
];
|
||||
// Do not allow users to set the anonymous or authenticated user roles as the
|
||||
// administrator role.
|
||||
$roles = user_role_names(TRUE);
|
||||
|
@ -114,7 +114,7 @@ class AccountSettingsForm extends ConfigFormBase {
|
|||
->execute();
|
||||
$default_value = reset($admin_roles);
|
||||
|
||||
$form['admin_role']['user_admin_role'] = array(
|
||||
$form['admin_role']['user_admin_role'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Administrator role'),
|
||||
'#empty_value' => '',
|
||||
|
@ -124,53 +124,53 @@ class AccountSettingsForm extends ConfigFormBase {
|
|||
// Don't allow to select a single admin role in case multiple roles got
|
||||
// marked as admin role already.
|
||||
'#access' => count($admin_roles) <= 1,
|
||||
);
|
||||
];
|
||||
|
||||
// @todo Remove this check once language settings are generalized.
|
||||
if ($this->moduleHandler->moduleExists('content_translation')) {
|
||||
$form['language'] = array(
|
||||
$form['language'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Language settings'),
|
||||
'#open' => TRUE,
|
||||
'#tree' => TRUE,
|
||||
);
|
||||
];
|
||||
$form_state->set(['content_translation', 'key'], 'language');
|
||||
$form['language'] += content_translation_enable_widget('user', 'user', $form, $form_state);
|
||||
}
|
||||
|
||||
// User registration settings.
|
||||
$form['registration_cancellation'] = array(
|
||||
$form['registration_cancellation'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Registration and cancellation'),
|
||||
'#open' => TRUE,
|
||||
);
|
||||
$form['registration_cancellation']['user_register'] = array(
|
||||
];
|
||||
$form['registration_cancellation']['user_register'] = [
|
||||
'#type' => 'radios',
|
||||
'#title' => $this->t('Who can register accounts?'),
|
||||
'#default_value' => $config->get('register'),
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
USER_REGISTER_ADMINISTRATORS_ONLY => $this->t('Administrators only'),
|
||||
USER_REGISTER_VISITORS => $this->t('Visitors'),
|
||||
USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL => $this->t('Visitors, but administrator approval is required'),
|
||||
)
|
||||
);
|
||||
$form['registration_cancellation']['user_email_verification'] = array(
|
||||
]
|
||||
];
|
||||
$form['registration_cancellation']['user_email_verification'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Require email verification when a visitor creates an account'),
|
||||
'#default_value' => $config->get('verify_mail'),
|
||||
'#description' => $this->t('New users will be required to validate their email address prior to logging into the site, and will be assigned a system-generated password. With this setting disabled, users will be logged in immediately upon registering, and may select their own passwords during registration.')
|
||||
);
|
||||
$form['registration_cancellation']['user_password_strength'] = array(
|
||||
];
|
||||
$form['registration_cancellation']['user_password_strength'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Enable password strength indicator'),
|
||||
'#default_value' => $config->get('password_strength'),
|
||||
);
|
||||
$form['registration_cancellation']['user_cancel_method'] = array(
|
||||
];
|
||||
$form['registration_cancellation']['user_cancel_method'] = [
|
||||
'#type' => 'radios',
|
||||
'#title' => $this->t('When cancelling a user account'),
|
||||
'#default_value' => $config->get('cancel_method'),
|
||||
'#description' => $this->t('Users with the %select-cancel-method or %administer-users <a href=":permissions-url">permissions</a> can override this default method.', array('%select-cancel-method' => $this->t('Select method for cancelling account'), '%administer-users' => $this->t('Administer users'), ':permissions-url' => $this->url('user.admin_permissions'))),
|
||||
);
|
||||
'#description' => $this->t('Users with the %select-cancel-method or %administer-users <a href=":permissions-url">permissions</a> can override this default method.', ['%select-cancel-method' => $this->t('Select method for cancelling account'), '%administer-users' => $this->t('Administer users'), ':permissions-url' => $this->url('user.admin_permissions')]),
|
||||
];
|
||||
$form['registration_cancellation']['user_cancel_method'] += user_cancel_methods();
|
||||
foreach (Element::children($form['registration_cancellation']['user_cancel_method']) as $key) {
|
||||
// All account cancellation methods that specify #access cannot be
|
||||
|
@ -182,239 +182,239 @@ class AccountSettingsForm extends ConfigFormBase {
|
|||
}
|
||||
|
||||
// Default notifications address.
|
||||
$form['mail_notification_address'] = array(
|
||||
$form['mail_notification_address'] = [
|
||||
'#type' => 'email',
|
||||
'#title' => $this->t('Notification email address'),
|
||||
'#default_value' => $site_config->get('mail_notification'),
|
||||
'#description' => $this->t("The email address to be used as the 'from' address for all account notifications listed below. If <em>'Visitors, but administrator approval is required'</em> is selected above, a notification email will also be sent to this address for any new registrations. Leave empty to use the default system email address <em>(%site-email).</em>", array('%site-email' => $site_config->get('mail'))),
|
||||
'#description' => $this->t("The email address to be used as the 'from' address for all account notifications listed below. If <em>'Visitors, but administrator approval is required'</em> is selected above, a notification email will also be sent to this address for any new registrations. Leave empty to use the default system email address <em>(%site-email).</em>", ['%site-email' => $site_config->get('mail')]),
|
||||
'#maxlength' => 180,
|
||||
);
|
||||
];
|
||||
|
||||
$form['email'] = array(
|
||||
$form['email'] = [
|
||||
'#type' => 'vertical_tabs',
|
||||
'#title' => $this->t('Emails'),
|
||||
);
|
||||
];
|
||||
// These email tokens are shared for all settings, so just define
|
||||
// the list once to help ensure they stay in sync.
|
||||
$email_token_help = $this->t('Available variables are: [site:name], [site:url], [user:display-name], [user:account-name], [user:mail], [site:login-url], [site:url-brief], [user:edit-url], [user:one-time-login-url], [user:cancel-url].');
|
||||
|
||||
$form['email_admin_created'] = array(
|
||||
$form['email_admin_created'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Welcome (new user created by administrator)'),
|
||||
'#open' => $config->get('register') == USER_REGISTER_ADMINISTRATORS_ONLY,
|
||||
'#description' => $this->t('Edit the welcome email messages sent to new member accounts created by an administrator.') . ' ' . $email_token_help,
|
||||
'#group' => 'email',
|
||||
);
|
||||
$form['email_admin_created']['user_mail_register_admin_created_subject'] = array(
|
||||
];
|
||||
$form['email_admin_created']['user_mail_register_admin_created_subject'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Subject'),
|
||||
'#default_value' => $mail_config->get('register_admin_created.subject'),
|
||||
'#maxlength' => 180,
|
||||
);
|
||||
$form['email_admin_created']['user_mail_register_admin_created_body'] = array(
|
||||
];
|
||||
$form['email_admin_created']['user_mail_register_admin_created_body'] = [
|
||||
'#type' => 'textarea',
|
||||
'#title' => $this->t('Body'),
|
||||
'#default_value' => $mail_config->get('register_admin_created.body'),
|
||||
'#rows' => 15,
|
||||
);
|
||||
];
|
||||
|
||||
$form['email_pending_approval'] = array(
|
||||
$form['email_pending_approval'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Welcome (awaiting approval)'),
|
||||
'#open' => $config->get('register') == USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL,
|
||||
'#description' => $this->t('Edit the welcome email messages sent to new members upon registering, when administrative approval is required.') . ' ' . $email_token_help,
|
||||
'#group' => 'email',
|
||||
);
|
||||
$form['email_pending_approval']['user_mail_register_pending_approval_subject'] = array(
|
||||
];
|
||||
$form['email_pending_approval']['user_mail_register_pending_approval_subject'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Subject'),
|
||||
'#default_value' => $mail_config->get('register_pending_approval.subject'),
|
||||
'#maxlength' => 180,
|
||||
);
|
||||
$form['email_pending_approval']['user_mail_register_pending_approval_body'] = array(
|
||||
];
|
||||
$form['email_pending_approval']['user_mail_register_pending_approval_body'] = [
|
||||
'#type' => 'textarea',
|
||||
'#title' => $this->t('Body'),
|
||||
'#default_value' => $mail_config->get('register_pending_approval.body'),
|
||||
'#rows' => 8,
|
||||
);
|
||||
];
|
||||
|
||||
$form['email_pending_approval_admin'] = array(
|
||||
$form['email_pending_approval_admin'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Admin (user awaiting approval)'),
|
||||
'#open' => $config->get('register') == USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL,
|
||||
'#description' => $this->t('Edit the email notifying the site administrator that there are new members awaiting administrative approval.') . ' ' . $email_token_help,
|
||||
'#group' => 'email',
|
||||
);
|
||||
$form['email_pending_approval_admin']['register_pending_approval_admin_subject'] = array(
|
||||
];
|
||||
$form['email_pending_approval_admin']['register_pending_approval_admin_subject'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Subject'),
|
||||
'#default_value' => $mail_config->get('register_pending_approval_admin.subject'),
|
||||
'#maxlength' => 180,
|
||||
);
|
||||
$form['email_pending_approval_admin']['register_pending_approval_admin_body'] = array(
|
||||
];
|
||||
$form['email_pending_approval_admin']['register_pending_approval_admin_body'] = [
|
||||
'#type' => 'textarea',
|
||||
'#title' => $this->t('Body'),
|
||||
'#default_value' => $mail_config->get('register_pending_approval_admin.body'),
|
||||
'#rows' => 8,
|
||||
);
|
||||
];
|
||||
|
||||
$form['email_no_approval_required'] = array(
|
||||
$form['email_no_approval_required'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Welcome (no approval required)'),
|
||||
'#open' => $config->get('register') == USER_REGISTER_VISITORS,
|
||||
'#description' => $this->t('Edit the welcome email messages sent to new members upon registering, when no administrator approval is required.') . ' ' . $email_token_help,
|
||||
'#group' => 'email',
|
||||
);
|
||||
$form['email_no_approval_required']['user_mail_register_no_approval_required_subject'] = array(
|
||||
];
|
||||
$form['email_no_approval_required']['user_mail_register_no_approval_required_subject'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Subject'),
|
||||
'#default_value' => $mail_config->get('register_no_approval_required.subject'),
|
||||
'#maxlength' => 180,
|
||||
);
|
||||
$form['email_no_approval_required']['user_mail_register_no_approval_required_body'] = array(
|
||||
];
|
||||
$form['email_no_approval_required']['user_mail_register_no_approval_required_body'] = [
|
||||
'#type' => 'textarea',
|
||||
'#title' => $this->t('Body'),
|
||||
'#default_value' => $mail_config->get('register_no_approval_required.body'),
|
||||
'#rows' => 15,
|
||||
);
|
||||
];
|
||||
|
||||
$form['email_password_reset'] = array(
|
||||
$form['email_password_reset'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Password recovery'),
|
||||
'#description' => $this->t('Edit the email messages sent to users who request a new password.') . ' ' . $email_token_help,
|
||||
'#group' => 'email',
|
||||
'#weight' => 10,
|
||||
);
|
||||
$form['email_password_reset']['user_mail_password_reset_subject'] = array(
|
||||
];
|
||||
$form['email_password_reset']['user_mail_password_reset_subject'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Subject'),
|
||||
'#default_value' => $mail_config->get('password_reset.subject'),
|
||||
'#maxlength' => 180,
|
||||
);
|
||||
$form['email_password_reset']['user_mail_password_reset_body'] = array(
|
||||
];
|
||||
$form['email_password_reset']['user_mail_password_reset_body'] = [
|
||||
'#type' => 'textarea',
|
||||
'#title' => $this->t('Body'),
|
||||
'#default_value' => $mail_config->get('password_reset.body'),
|
||||
'#rows' => 12,
|
||||
);
|
||||
];
|
||||
|
||||
$form['email_activated'] = array(
|
||||
$form['email_activated'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Account activation'),
|
||||
'#description' => $this->t('Enable and edit email messages sent to users upon account activation (when an administrator activates an account of a user who has already registered, on a site where administrative approval is required).') . ' ' . $email_token_help,
|
||||
'#group' => 'email',
|
||||
);
|
||||
$form['email_activated']['user_mail_status_activated_notify'] = array(
|
||||
];
|
||||
$form['email_activated']['user_mail_status_activated_notify'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Notify user when account is activated'),
|
||||
'#default_value' => $config->get('notify.status_activated'),
|
||||
);
|
||||
$form['email_activated']['settings'] = array(
|
||||
];
|
||||
$form['email_activated']['settings'] = [
|
||||
'#type' => 'container',
|
||||
'#states' => array(
|
||||
'#states' => [
|
||||
// Hide the additional settings when this email is disabled.
|
||||
'invisible' => array(
|
||||
'input[name="user_mail_status_activated_notify"]' => array('checked' => FALSE),
|
||||
),
|
||||
),
|
||||
);
|
||||
$form['email_activated']['settings']['user_mail_status_activated_subject'] = array(
|
||||
'invisible' => [
|
||||
'input[name="user_mail_status_activated_notify"]' => ['checked' => FALSE],
|
||||
],
|
||||
],
|
||||
];
|
||||
$form['email_activated']['settings']['user_mail_status_activated_subject'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Subject'),
|
||||
'#default_value' => $mail_config->get('status_activated.subject'),
|
||||
'#maxlength' => 180,
|
||||
);
|
||||
$form['email_activated']['settings']['user_mail_status_activated_body'] = array(
|
||||
];
|
||||
$form['email_activated']['settings']['user_mail_status_activated_body'] = [
|
||||
'#type' => 'textarea',
|
||||
'#title' => $this->t('Body'),
|
||||
'#default_value' => $mail_config->get('status_activated.body'),
|
||||
'#rows' => 15,
|
||||
);
|
||||
];
|
||||
|
||||
$form['email_blocked'] = array(
|
||||
$form['email_blocked'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Account blocked'),
|
||||
'#description' => $this->t('Enable and edit email messages sent to users when their accounts are blocked.') . ' ' . $email_token_help,
|
||||
'#group' => 'email',
|
||||
);
|
||||
$form['email_blocked']['user_mail_status_blocked_notify'] = array(
|
||||
];
|
||||
$form['email_blocked']['user_mail_status_blocked_notify'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Notify user when account is blocked'),
|
||||
'#default_value' => $config->get('notify.status_blocked'),
|
||||
);
|
||||
$form['email_blocked']['settings'] = array(
|
||||
];
|
||||
$form['email_blocked']['settings'] = [
|
||||
'#type' => 'container',
|
||||
'#states' => array(
|
||||
'#states' => [
|
||||
// Hide the additional settings when the blocked email is disabled.
|
||||
'invisible' => array(
|
||||
'input[name="user_mail_status_blocked_notify"]' => array('checked' => FALSE),
|
||||
),
|
||||
),
|
||||
);
|
||||
$form['email_blocked']['settings']['user_mail_status_blocked_subject'] = array(
|
||||
'invisible' => [
|
||||
'input[name="user_mail_status_blocked_notify"]' => ['checked' => FALSE],
|
||||
],
|
||||
],
|
||||
];
|
||||
$form['email_blocked']['settings']['user_mail_status_blocked_subject'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Subject'),
|
||||
'#default_value' => $mail_config->get('status_blocked.subject'),
|
||||
'#maxlength' => 180,
|
||||
);
|
||||
$form['email_blocked']['settings']['user_mail_status_blocked_body'] = array(
|
||||
];
|
||||
$form['email_blocked']['settings']['user_mail_status_blocked_body'] = [
|
||||
'#type' => 'textarea',
|
||||
'#title' => $this->t('Body'),
|
||||
'#default_value' => $mail_config->get('status_blocked.body'),
|
||||
'#rows' => 3,
|
||||
);
|
||||
];
|
||||
|
||||
$form['email_cancel_confirm'] = array(
|
||||
$form['email_cancel_confirm'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Account cancellation confirmation'),
|
||||
'#description' => $this->t('Edit the email messages sent to users when they attempt to cancel their accounts.') . ' ' . $email_token_help,
|
||||
'#group' => 'email',
|
||||
);
|
||||
$form['email_cancel_confirm']['user_mail_cancel_confirm_subject'] = array(
|
||||
];
|
||||
$form['email_cancel_confirm']['user_mail_cancel_confirm_subject'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Subject'),
|
||||
'#default_value' => $mail_config->get('cancel_confirm.subject'),
|
||||
'#maxlength' => 180,
|
||||
);
|
||||
$form['email_cancel_confirm']['user_mail_cancel_confirm_body'] = array(
|
||||
];
|
||||
$form['email_cancel_confirm']['user_mail_cancel_confirm_body'] = [
|
||||
'#type' => 'textarea',
|
||||
'#title' => $this->t('Body'),
|
||||
'#default_value' => $mail_config->get('cancel_confirm.body'),
|
||||
'#rows' => 3,
|
||||
);
|
||||
];
|
||||
|
||||
$form['email_canceled'] = array(
|
||||
$form['email_canceled'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Account canceled'),
|
||||
'#description' => $this->t('Enable and edit email messages sent to users when their accounts are canceled.') . ' ' . $email_token_help,
|
||||
'#group' => 'email',
|
||||
);
|
||||
$form['email_canceled']['user_mail_status_canceled_notify'] = array(
|
||||
];
|
||||
$form['email_canceled']['user_mail_status_canceled_notify'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Notify user when account is canceled'),
|
||||
'#default_value' => $config->get('notify.status_canceled'),
|
||||
);
|
||||
$form['email_canceled']['settings'] = array(
|
||||
];
|
||||
$form['email_canceled']['settings'] = [
|
||||
'#type' => 'container',
|
||||
'#states' => array(
|
||||
'#states' => [
|
||||
// Hide the settings when the cancel notify checkbox is disabled.
|
||||
'invisible' => array(
|
||||
'input[name="user_mail_status_canceled_notify"]' => array('checked' => FALSE),
|
||||
),
|
||||
),
|
||||
);
|
||||
$form['email_canceled']['settings']['user_mail_status_canceled_subject'] = array(
|
||||
'invisible' => [
|
||||
'input[name="user_mail_status_canceled_notify"]' => ['checked' => FALSE],
|
||||
],
|
||||
],
|
||||
];
|
||||
$form['email_canceled']['settings']['user_mail_status_canceled_subject'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Subject'),
|
||||
'#default_value' => $mail_config->get('status_canceled.subject'),
|
||||
'#maxlength' => 180,
|
||||
);
|
||||
$form['email_canceled']['settings']['user_mail_status_canceled_body'] = array(
|
||||
];
|
||||
$form['email_canceled']['settings']['user_mail_status_canceled_body'] = [
|
||||
'#type' => 'textarea',
|
||||
'#title' => $this->t('Body'),
|
||||
'#default_value' => $mail_config->get('status_canceled.body'),
|
||||
'#rows' => 3,
|
||||
);
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@ class UserController extends ControllerBase {
|
|||
/** @var \Drupal\user\UserInterface $reset_link_user */
|
||||
if ($reset_link_user = $this->userStorage->load($uid)) {
|
||||
drupal_set_message($this->t('Another user (%other_user) is already logged into the site on this computer, but you tried to use a one-time link for user %resetting_user. Please <a href=":logout">log out</a> and try using the link again.',
|
||||
array('%other_user' => $account->getUsername(), '%resetting_user' => $reset_link_user->getUsername(), ':logout' => $this->url('user.logout'))), 'warning');
|
||||
['%other_user' => $account->getUsername(), '%resetting_user' => $reset_link_user->getUsername(), ':logout' => $this->url('user.logout')]), 'warning');
|
||||
}
|
||||
else {
|
||||
// Invalid one-time link specifies an unknown user.
|
||||
|
@ -254,7 +254,7 @@ class UserController extends ControllerBase {
|
|||
* Returns a redirect to the profile of the currently logged in user.
|
||||
*/
|
||||
public function userPage() {
|
||||
return $this->redirect('entity.user.canonical', array('user' => $this->currentUser()->id()));
|
||||
return $this->redirect('entity.user.canonical', ['user' => $this->currentUser()->id()]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -305,9 +305,9 @@ class UserController extends ControllerBase {
|
|||
if (isset($account_data['cancel_method']) && !empty($timestamp) && !empty($hashed_pass)) {
|
||||
// Validate expiration and hashed password/login.
|
||||
if ($timestamp <= $current && $current - $timestamp < $timeout && $user->id() && $timestamp >= $user->getLastLoginTime() && Crypt::hashEquals($hashed_pass, user_pass_rehash($user, $timestamp))) {
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'user_cancel_notify' => isset($account_data['cancel_notify']) ? $account_data['cancel_notify'] : $this->config('user.settings')->get('notify.status_canceled'),
|
||||
);
|
||||
];
|
||||
user_cancel($edit, $user->id(), $account_data['cancel_method']);
|
||||
// Since user_cancel() is not invoked via Form API, batch processing
|
||||
// needs to be invoked manually and should redirect to the front page
|
||||
|
|
|
@ -72,7 +72,7 @@ class Role extends ConfigEntityBase implements RoleInterface {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $permissions = array();
|
||||
protected $permissions = [];
|
||||
|
||||
/**
|
||||
* An indicator whether the role has all permissions.
|
||||
|
@ -136,7 +136,7 @@ class Role extends ConfigEntityBase implements RoleInterface {
|
|||
if ($this->isAdmin()) {
|
||||
return $this;
|
||||
}
|
||||
$this->permissions = array_diff($this->permissions, array($permission));
|
||||
$this->permissions = array_diff($this->permissions, [$permission]);
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -178,6 +178,12 @@ class Role extends ConfigEntityBase implements RoleInterface {
|
|||
});
|
||||
$this->weight = $max + 1;
|
||||
}
|
||||
|
||||
if (!$this->isSyncing()) {
|
||||
// Permissions are always ordered alphabetically to avoid conflicts in the
|
||||
// exported configuration.
|
||||
sort($this->permissions);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -82,13 +82,13 @@ class User extends ContentEntityBase implements UserInterface {
|
|||
|
||||
// Make sure that the authenticated/anonymous roles are not persisted.
|
||||
foreach ($this->get('roles') as $index => $item) {
|
||||
if (in_array($item->target_id, array(RoleInterface::ANONYMOUS_ID, RoleInterface::AUTHENTICATED_ID))) {
|
||||
if (in_array($item->target_id, [RoleInterface::ANONYMOUS_ID, RoleInterface::AUTHENTICATED_ID])) {
|
||||
$this->get('roles')->offsetUnset($index);
|
||||
}
|
||||
}
|
||||
|
||||
// Store account cancellation information.
|
||||
foreach (array('user_cancel_method', 'user_cancel_notify') as $key) {
|
||||
foreach (['user_cancel_method', 'user_cancel_notify'] as $key) {
|
||||
if (isset($this->{$key})) {
|
||||
\Drupal::service('user.data')->set('user', $this->id(), substr($key, 5), $this->{$key});
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ class User extends ContentEntityBase implements UserInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRoles($exclude_locked_roles = FALSE) {
|
||||
$roles = array();
|
||||
$roles = [];
|
||||
|
||||
// Users with an ID always have the authenticated user role.
|
||||
if (!$exclude_locked_roles) {
|
||||
|
@ -186,7 +186,7 @@ class User extends ContentEntityBase implements UserInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function removeRole($rid) {
|
||||
$this->set('roles', array_diff($this->getRoles(TRUE), array($rid)));
|
||||
$this->set('roles', array_diff($this->getRoles(TRUE), [$rid]));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -308,7 +308,7 @@ class User extends ContentEntityBase implements UserInterface {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function getPreferredLangcode($fallback_to_default = TRUE) {
|
||||
public function getPreferredLangcode($fallback_to_default = TRUE) {
|
||||
$language_list = $this->languageManager()->getLanguages();
|
||||
$preferred_langcode = $this->get('preferred_langcode')->value;
|
||||
if (!empty($preferred_langcode) && isset($language_list[$preferred_langcode])) {
|
||||
|
@ -322,7 +322,7 @@ class User extends ContentEntityBase implements UserInterface {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function getPreferredAdminLangcode($fallback_to_default = TRUE) {
|
||||
public function getPreferredAdminLangcode($fallback_to_default = TRUE) {
|
||||
$language_list = $this->languageManager()->getLanguages();
|
||||
$preferred_langcode = $this->get('preferred_admin_langcode')->value;
|
||||
if (!empty($preferred_langcode) && isset($language_list[$preferred_langcode])) {
|
||||
|
@ -438,16 +438,16 @@ class User extends ContentEntityBase implements UserInterface {
|
|||
|
||||
$fields['langcode']->setLabel(t('Language code'))
|
||||
->setDescription(t('The user language code.'))
|
||||
->setDisplayOptions('form', ['type' => 'hidden']);
|
||||
->setDisplayOptions('form', ['region' => 'hidden']);
|
||||
|
||||
$fields['preferred_langcode'] = BaseFieldDefinition::create('language')
|
||||
->setLabel(t('Preferred language code'))
|
||||
->setDescription(t("The user's preferred language code for receiving emails and viewing the site."))
|
||||
// @todo: Define this via an options provider once
|
||||
// https://www.drupal.org/node/2329937 is completed.
|
||||
->addPropertyConstraints('value', array(
|
||||
'AllowedValues' => array('callback' => __CLASS__ . '::getAllowedConfigurableLanguageCodes'),
|
||||
));
|
||||
->addPropertyConstraints('value', [
|
||||
'AllowedValues' => ['callback' => __CLASS__ . '::getAllowedConfigurableLanguageCodes'],
|
||||
]);
|
||||
|
||||
$fields['preferred_admin_langcode'] = BaseFieldDefinition::create('language')
|
||||
->setLabel(t('Preferred admin language code'))
|
||||
|
@ -455,12 +455,12 @@ class User extends ContentEntityBase implements UserInterface {
|
|||
// @todo: A default value of NULL is ignored, so we have to specify
|
||||
// an empty field item structure instead. Fix this in
|
||||
// https://www.drupal.org/node/2318605.
|
||||
->setDefaultValue(array(0 => array ('value' => NULL)))
|
||||
->setDefaultValue([0 => ['value' => NULL]])
|
||||
// @todo: Define this via an options provider once
|
||||
// https://www.drupal.org/node/2329937 is completed.
|
||||
->addPropertyConstraints('value', array(
|
||||
'AllowedValues' => array('callback' => __CLASS__ . '::getAllowedConfigurableLanguageCodes'),
|
||||
));
|
||||
->addPropertyConstraints('value', [
|
||||
'AllowedValues' => ['callback' => __CLASS__ . '::getAllowedConfigurableLanguageCodes'],
|
||||
]);
|
||||
|
||||
// The name should not vary per language. The username is the visual
|
||||
// identifier for a user and needs to be consistent in all languages.
|
||||
|
@ -468,12 +468,12 @@ class User extends ContentEntityBase implements UserInterface {
|
|||
->setLabel(t('Name'))
|
||||
->setDescription(t('The name of this user.'))
|
||||
->setRequired(TRUE)
|
||||
->setConstraints(array(
|
||||
->setConstraints([
|
||||
// No Length constraint here because the UserName constraint also covers
|
||||
// that.
|
||||
'UserName' => array(),
|
||||
'UserNameUnique' => array(),
|
||||
));
|
||||
'UserName' => [],
|
||||
'UserNameUnique' => [],
|
||||
]);
|
||||
$fields['name']->getItemDefinition()->setClass('\Drupal\user\UserNameItem');
|
||||
|
||||
$fields['pass'] = BaseFieldDefinition::create('password')
|
||||
|
@ -495,9 +495,9 @@ class User extends ContentEntityBase implements UserInterface {
|
|||
->setSetting('max_length', 32)
|
||||
// @todo: Define this via an options provider once
|
||||
// https://www.drupal.org/node/2329937 is completed.
|
||||
->addPropertyConstraints('value', array(
|
||||
'AllowedValues' => array('callback' => __CLASS__ . '::getAllowedTimezones'),
|
||||
));
|
||||
->addPropertyConstraints('value', [
|
||||
'AllowedValues' => ['callback' => __CLASS__ . '::getAllowedTimezones'],
|
||||
]);
|
||||
|
||||
$fields['status'] = BaseFieldDefinition::create('boolean')
|
||||
->setLabel(t('User status'))
|
||||
|
|
|
@ -31,7 +31,7 @@ class UserCancelForm extends ContentEntityConfirmFormBase {
|
|||
if ($this->entity->id() == $this->currentUser()->id()) {
|
||||
return $this->t('Are you sure you want to cancel your account?');
|
||||
}
|
||||
return $this->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?', ['%name' => $this->entity->label()]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -74,43 +74,43 @@ class UserCancelForm extends ContentEntityConfirmFormBase {
|
|||
|
||||
// Display account cancellation method selection, if allowed.
|
||||
$admin_access = $user->hasPermission('administer users');
|
||||
$form['user_cancel_method'] = array(
|
||||
$form['user_cancel_method'] = [
|
||||
'#type' => 'radios',
|
||||
'#title' => ($this->entity->id() == $user->id() ? $this->t('When cancelling your account') : $this->t('When cancelling the account')),
|
||||
'#access' => $admin_access || $user->hasPermission('select account cancellation method'),
|
||||
);
|
||||
];
|
||||
$form['user_cancel_method'] += $this->cancelMethods;
|
||||
|
||||
// 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());
|
||||
$form['user_cancel_confirm'] = array(
|
||||
$form['user_cancel_confirm'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Require email confirmation to cancel account'),
|
||||
'#default_value' => !$override_access,
|
||||
'#access' => $override_access,
|
||||
'#description' => $this->t('When enabled, the user must confirm the account cancellation via email.'),
|
||||
);
|
||||
];
|
||||
// Also allow to send account canceled notification mail, if enabled.
|
||||
$default_notify = $this->config('user.settings')->get('notify.status_canceled');
|
||||
$form['user_cancel_notify'] = array(
|
||||
$form['user_cancel_notify'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Notify user when account is canceled'),
|
||||
'#default_value' => ($override_access ? FALSE : $default_notify),
|
||||
'#access' => $override_access && $default_notify,
|
||||
'#description' => $this->t('When enabled, the user will receive an email 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());
|
||||
$form['uid'] = ['#type' => 'value', '#value' => $this->entity->id()];
|
||||
|
||||
// Store the user permissions so that it can be altered in hook_form_alter()
|
||||
// if desired.
|
||||
$form['access'] = array(
|
||||
$form['access'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => $user->hasPermission('administer users'),
|
||||
);
|
||||
];
|
||||
|
||||
$form = parent::buildForm($form, $form_state);
|
||||
|
||||
|
@ -138,11 +138,11 @@ class UserCancelForm extends ContentEntityConfirmFormBase {
|
|||
$this->entity->save();
|
||||
_user_mail_notify('cancel_confirm', $this->entity);
|
||||
drupal_set_message($this->t('A confirmation request to cancel your account has been sent to your email address.'));
|
||||
$this->logger('user')->notice('Sent account cancellation request to %name %email.', array('%name' => $this->entity->label(), '%email' => '<' . $this->entity->getEmail() . '>'));
|
||||
$this->logger('user')->notice('Sent account cancellation request to %name %email.', ['%name' => $this->entity->label(), '%email' => '<' . $this->entity->getEmail() . '>']);
|
||||
|
||||
$form_state->setRedirect(
|
||||
'entity.user.canonical',
|
||||
array('user' => $this->entity->id())
|
||||
['user' => $this->entity->id()]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,31 +88,31 @@ class UserLoginForm extends FormBase {
|
|||
$config = $this->config('system.site');
|
||||
|
||||
// Display login form:
|
||||
$form['name'] = array(
|
||||
$form['name'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Username'),
|
||||
'#size' => 60,
|
||||
'#maxlength' => USERNAME_MAX_LENGTH,
|
||||
'#description' => $this->t('Enter your @s username.', array('@s' => $config->get('name'))),
|
||||
'#description' => $this->t('Enter your @s username.', ['@s' => $config->get('name')]),
|
||||
'#required' => TRUE,
|
||||
'#attributes' => array(
|
||||
'#attributes' => [
|
||||
'autocorrect' => 'none',
|
||||
'autocapitalize' => 'none',
|
||||
'spellcheck' => 'false',
|
||||
'autofocus' => 'autofocus',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
$form['pass'] = array(
|
||||
$form['pass'] = [
|
||||
'#type' => 'password',
|
||||
'#title' => $this->t('Password'),
|
||||
'#size' => 60,
|
||||
'#description' => $this->t('Enter the password that accompanies your username.'),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
];
|
||||
|
||||
$form['actions'] = array('#type' => 'actions');
|
||||
$form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Log in'));
|
||||
$form['actions'] = ['#type' => 'actions'];
|
||||
$form['actions']['submit'] = ['#type' => 'submit', '#value' => $this->t('Log in')];
|
||||
|
||||
$form['#validate'][] = '::validateName';
|
||||
$form['#validate'][] = '::validateAuthentication';
|
||||
|
@ -133,7 +133,7 @@ class UserLoginForm extends FormBase {
|
|||
if (!$this->getRequest()->request->has('destination')) {
|
||||
$form_state->setRedirect(
|
||||
'entity.user.canonical',
|
||||
array('user' => $account->id())
|
||||
['user' => $account->id()]
|
||||
);
|
||||
}
|
||||
else {
|
||||
|
@ -149,7 +149,7 @@ class UserLoginForm extends FormBase {
|
|||
public function validateName(array &$form, FormStateInterface $form_state) {
|
||||
if (!$form_state->isValueEmpty('name') && user_is_blocked($form_state->getValue('name'))) {
|
||||
// Blocked in user administration.
|
||||
$form_state->setErrorByName('name', $this->t('The username %name has not been activated or is blocked.', array('%name' => $form_state->getValue('name'))));
|
||||
$form_state->setErrorByName('name', $this->t('The username %name has not been activated or is blocked.', ['%name' => $form_state->getValue('name')]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -171,7 +171,7 @@ class UserLoginForm extends FormBase {
|
|||
$form_state->set('flood_control_triggered', 'ip');
|
||||
return;
|
||||
}
|
||||
$accounts = $this->userStorage->loadByProperties(array('name' => $form_state->getValue('name'), 'status' => 1));
|
||||
$accounts = $this->userStorage->loadByProperties(['name' => $form_state->getValue('name'), 'status' => 1]);
|
||||
$account = reset($accounts);
|
||||
if ($account) {
|
||||
if ($flood_config->get('uid_only')) {
|
||||
|
@ -218,11 +218,11 @@ class UserLoginForm extends FormBase {
|
|||
|
||||
if ($flood_control_triggered = $form_state->get('flood_control_triggered')) {
|
||||
if ($flood_control_triggered == 'user') {
|
||||
$form_state->setErrorByName('name', $this->formatPlural($flood_config->get('user_limit'), 'There has been more than one failed login attempt for this account. It is temporarily blocked. Try again later or <a href=":url">request a new password</a>.', 'There have been more than @count failed login attempts for this account. It is temporarily blocked. Try again later or <a href=":url">request a new password</a>.', array(':url' => $this->url('user.pass'))));
|
||||
$form_state->setErrorByName('name', $this->formatPlural($flood_config->get('user_limit'), 'There has been more than one failed login attempt for this account. It is temporarily blocked. Try again later or <a href=":url">request a new password</a>.', 'There have been more than @count failed login attempts for this account. It is temporarily blocked. Try again later or <a href=":url">request a new password</a>.', [':url' => $this->url('user.pass')]));
|
||||
}
|
||||
else {
|
||||
// We did not find a uid, so the limit is IP-based.
|
||||
$form_state->setErrorByName('name', $this->t('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' => $this->url('user.pass'))));
|
||||
$form_state->setErrorByName('name', $this->t('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>.', [':url' => $this->url('user.pass')]));
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -231,16 +231,16 @@ class UserLoginForm extends FormBase {
|
|||
// $form_state->getValue() may have been modified by validation
|
||||
// handlers that ran earlier than this one.
|
||||
$user_input = $form_state->getUserInput();
|
||||
$query = isset($user_input['name']) ? array('name' => $user_input['name']) : array();
|
||||
$form_state->setErrorByName('name', $this->t('Unrecognized username or password. <a href=":password">Forgot your password?</a>', array(':password' => $this->url('user.pass', [], array('query' => $query)))));
|
||||
$accounts = $this->userStorage->loadByProperties(array('name' => $form_state->getValue('name')));
|
||||
$query = isset($user_input['name']) ? ['name' => $user_input['name']] : [];
|
||||
$form_state->setErrorByName('name', $this->t('Unrecognized username or password. <a href=":password">Forgot your password?</a>', [':password' => $this->url('user.pass', [], ['query' => $query])]));
|
||||
$accounts = $this->userStorage->loadByProperties(['name' => $form_state->getValue('name')]);
|
||||
if (!empty($accounts)) {
|
||||
$this->logger('user')->notice('Login attempt failed for %user.', array('%user' => $form_state->getValue('name')));
|
||||
$this->logger('user')->notice('Login attempt failed for %user.', ['%user' => $form_state->getValue('name')]);
|
||||
}
|
||||
else {
|
||||
// If the username entered is not a valid user,
|
||||
// only store the IP address.
|
||||
$this->logger('user')->notice('Login attempt failed from %ip.', array('%ip' => $this->getRequest()->getClientIp()));
|
||||
$this->logger('user')->notice('Login attempt failed from %ip.', ['%ip' => $this->getRequest()->getClientIp()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,6 +96,7 @@ class UserMultipleCancelConfirm extends ConfirmFormBase {
|
|||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
// Retrieve the accounts to be canceled from the temp store.
|
||||
/* @var \Drupal\user\Entity\User[] $accounts */
|
||||
$accounts = $this->tempStoreFactory
|
||||
->get('user_user_operations_cancel')
|
||||
->get($this->currentUser()->id());
|
||||
|
@ -104,26 +105,31 @@ class UserMultipleCancelConfirm extends ConfirmFormBase {
|
|||
}
|
||||
|
||||
$root = NULL;
|
||||
$form['accounts'] = array('#prefix' => '<ul>', '#suffix' => '</ul>', '#tree' => TRUE);
|
||||
$names = [];
|
||||
$form['accounts'] = ['#tree' => TRUE];
|
||||
foreach ($accounts as $account) {
|
||||
$uid = $account->id();
|
||||
$names[$uid] = $account->label();
|
||||
// Prevent user 1 from being canceled.
|
||||
if ($uid <= 1) {
|
||||
$root = intval($uid) === 1 ? $account : $root;
|
||||
continue;
|
||||
}
|
||||
$form['accounts'][$uid] = array(
|
||||
$form['accounts'][$uid] = [
|
||||
'#type' => 'hidden',
|
||||
'#value' => $uid,
|
||||
'#prefix' => '<li>',
|
||||
'#suffix' => $account->label() . "</li>\n",
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
$form['account']['names'] = [
|
||||
'#theme' => 'item_list',
|
||||
'#items' => $names,
|
||||
];
|
||||
|
||||
// Output a notice that user 1 cannot be canceled.
|
||||
if (isset($root)) {
|
||||
$redirect = (count($accounts) == 1);
|
||||
$message = $this->t('The user account %name cannot be canceled.', array('%name' => $root->label()));
|
||||
$message = $this->t('The user account %name cannot be canceled.', ['%name' => $root->label()]);
|
||||
drupal_set_message($message, $redirect ? 'error' : 'warning');
|
||||
// If only user 1 was selected, redirect to the overview.
|
||||
if ($redirect) {
|
||||
|
@ -131,30 +137,30 @@ class UserMultipleCancelConfirm extends ConfirmFormBase {
|
|||
}
|
||||
}
|
||||
|
||||
$form['operation'] = array('#type' => 'hidden', '#value' => 'cancel');
|
||||
$form['operation'] = ['#type' => 'hidden', '#value' => 'cancel'];
|
||||
|
||||
$form['user_cancel_method'] = array(
|
||||
$form['user_cancel_method'] = [
|
||||
'#type' => 'radios',
|
||||
'#title' => $this->t('When cancelling these accounts'),
|
||||
);
|
||||
];
|
||||
|
||||
$form['user_cancel_method'] += user_cancel_methods();
|
||||
|
||||
// Allow to send the account cancellation confirmation mail.
|
||||
$form['user_cancel_confirm'] = array(
|
||||
$form['user_cancel_confirm'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Require email confirmation to cancel account'),
|
||||
'#default_value' => FALSE,
|
||||
'#description' => $this->t('When enabled, the user must confirm the account cancellation via email.'),
|
||||
);
|
||||
];
|
||||
// Also allow to send account canceled notification mail, if enabled.
|
||||
$form['user_cancel_notify'] = array(
|
||||
$form['user_cancel_notify'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Notify user when account is canceled'),
|
||||
'#default_value' => FALSE,
|
||||
'#access' => $this->config('user.settings')->get('notify.status_canceled'),
|
||||
'#description' => $this->t('When enabled, the user will receive an email notification after the account has been canceled.'),
|
||||
);
|
||||
];
|
||||
|
||||
$form = parent::buildForm($form, $form_state);
|
||||
|
||||
|
@ -177,7 +183,7 @@ class UserMultipleCancelConfirm extends ConfirmFormBase {
|
|||
}
|
||||
// Prevent user administrators from deleting themselves without confirmation.
|
||||
if ($uid == $current_user_id) {
|
||||
$admin_form_mock = array();
|
||||
$admin_form_mock = [];
|
||||
$admin_form_state = $form_state;
|
||||
$admin_form_state->unsetValue('user_cancel_confirm');
|
||||
// The $user global is not a complete user entity, so load the full
|
||||
|
|
|
@ -65,40 +65,40 @@ class UserPasswordForm extends FormBase {
|
|||
* The request object.
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$form['name'] = array(
|
||||
$form['name'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Username or email address'),
|
||||
'#size' => 60,
|
||||
'#maxlength' => max(USERNAME_MAX_LENGTH, Email::EMAIL_MAX_LENGTH),
|
||||
'#required' => TRUE,
|
||||
'#attributes' => array(
|
||||
'#attributes' => [
|
||||
'autocorrect' => 'off',
|
||||
'autocapitalize' => 'off',
|
||||
'spellcheck' => 'false',
|
||||
'autofocus' => 'autofocus',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
// Allow logged in users to request this also.
|
||||
$user = $this->currentUser();
|
||||
if ($user->isAuthenticated()) {
|
||||
$form['name']['#type'] = 'value';
|
||||
$form['name']['#value'] = $user->getEmail();
|
||||
$form['mail'] = array(
|
||||
$form['mail'] = [
|
||||
'#prefix' => '<p>',
|
||||
'#markup' => $this->t('Password reset instructions will be mailed to %email. You must log out to use the password reset link in the email.', 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 email.', ['%email' => $user->getEmail()]),
|
||||
'#suffix' => '</p>',
|
||||
);
|
||||
];
|
||||
}
|
||||
else {
|
||||
$form['mail'] = array(
|
||||
$form['mail'] = [
|
||||
'#prefix' => '<p>',
|
||||
'#markup' => $this->t('Password reset instructions will be sent to your registered email address.'),
|
||||
'#suffix' => '</p>',
|
||||
);
|
||||
];
|
||||
$form['name']['#default_value'] = $this->getRequest()->query->get('name');
|
||||
}
|
||||
$form['actions'] = array('#type' => 'actions');
|
||||
$form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Submit'));
|
||||
$form['actions'] = ['#type' => 'actions'];
|
||||
$form['actions']['submit'] = ['#type' => 'submit', '#value' => $this->t('Submit')];
|
||||
$form['#cache']['contexts'][] = 'url.query_args';
|
||||
|
||||
return $form;
|
||||
|
@ -110,23 +110,23 @@ class UserPasswordForm extends FormBase {
|
|||
public function validateForm(array &$form, FormStateInterface $form_state) {
|
||||
$name = trim($form_state->getValue('name'));
|
||||
// Try to load by email.
|
||||
$users = $this->userStorage->loadByProperties(array('mail' => $name));
|
||||
$users = $this->userStorage->loadByProperties(['mail' => $name]);
|
||||
if (empty($users)) {
|
||||
// No success, try to load by name.
|
||||
$users = $this->userStorage->loadByProperties(array('name' => $name));
|
||||
$users = $this->userStorage->loadByProperties(['name' => $name]);
|
||||
}
|
||||
$account = reset($users);
|
||||
if ($account && $account->id()) {
|
||||
// Blocked accounts cannot request a new password.
|
||||
if (!$account->isActive()) {
|
||||
$form_state->setErrorByName('name', $this->t('%name is blocked or has not been activated yet.', array('%name' => $name)));
|
||||
$form_state->setErrorByName('name', $this->t('%name is blocked or has not been activated yet.', ['%name' => $name]));
|
||||
}
|
||||
else {
|
||||
$form_state->setValueForElement(array('#parents' => array('account')), $account);
|
||||
$form_state->setValueForElement(['#parents' => ['account']], $account);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$form_state->setErrorByName('name', $this->t('%name is not recognized as a username or an email address.', array('%name' => $name)));
|
||||
$form_state->setErrorByName('name', $this->t('%name is not recognized as a username or an email address.', ['%name' => $name]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -140,7 +140,7 @@ class UserPasswordForm extends FormBase {
|
|||
// Mail one time login URL and instructions using current language.
|
||||
$mail = _user_mail_notify('password_reset', $account, $langcode);
|
||||
if (!empty($mail)) {
|
||||
$this->logger('user')->notice('Password reset instructions mailed to %name at %email.', array('%name' => $account->getUsername(), '%email' => $account->getEmail()));
|
||||
$this->logger('user')->notice('Password reset instructions mailed to %name at %email.', ['%name' => $account->getUsername(), '%email' => $account->getEmail()]);
|
||||
drupal_set_message($this->t('Further instructions have been sent to your email address.'));
|
||||
}
|
||||
|
||||
|
|
|
@ -38,21 +38,21 @@ class UserPasswordResetForm extends FormBase {
|
|||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state, AccountInterface $user = NULL, $expiration_date = NULL, $timestamp = NULL, $hash = NULL) {
|
||||
if ($expiration_date) {
|
||||
$form['message'] = array('#markup' => $this->t('<p>This is a one-time login for %user_name and will expire on %expiration_date.</p><p>Click on this button to log in to the site and change your password.</p>', array('%user_name' => $user->getUsername(), '%expiration_date' => $expiration_date)));
|
||||
$form['message'] = ['#markup' => $this->t('<p>This is a one-time login for %user_name and will expire on %expiration_date.</p><p>Click on this button to log in to the site and change your password.</p>', ['%user_name' => $user->getUsername(), '%expiration_date' => $expiration_date])];
|
||||
$form['#title'] = $this->t('Reset password');
|
||||
}
|
||||
else {
|
||||
// No expiration for first time login.
|
||||
$form['message'] = array('#markup' => $this->t('<p>This is a one-time login for %user_name.</p><p>Click on this button to log in to the site and change your password.</p>', array('%user_name' => $user->getUsername())));
|
||||
$form['message'] = ['#markup' => $this->t('<p>This is a one-time login for %user_name.</p><p>Click on this button to log in to the site and change your password.</p>', ['%user_name' => $user->getUsername()])];
|
||||
$form['#title'] = $this->t('Set password');
|
||||
}
|
||||
|
||||
$form['help'] = array('#markup' => '<p>' . $this->t('This login can be used only once.') . '</p>');
|
||||
$form['actions'] = array('#type' => 'actions');
|
||||
$form['actions']['submit'] = array(
|
||||
$form['help'] = ['#markup' => '<p>' . $this->t('This login can be used only once.') . '</p>'];
|
||||
$form['actions'] = ['#type' => 'actions'];
|
||||
$form['actions']['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Log in'),
|
||||
);
|
||||
];
|
||||
$form['#action'] = Url::fromRoute('user.reset.login', [
|
||||
'uid' => $user->id(),
|
||||
'timestamp' => $timestamp,
|
||||
|
|
|
@ -83,9 +83,9 @@ class UserPermissionsForm extends FormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$role_names = array();
|
||||
$role_permissions = array();
|
||||
$admin_roles = array();
|
||||
$role_names = [];
|
||||
$role_permissions = [];
|
||||
$admin_roles = [];
|
||||
foreach ($this->getRoles() as $role_name => $role) {
|
||||
// Retrieve role names for columns.
|
||||
$role_names[$role_name] = $role->label();
|
||||
|
@ -95,79 +95,79 @@ class UserPermissionsForm extends FormBase {
|
|||
}
|
||||
|
||||
// Store $role_names for use when saving the data.
|
||||
$form['role_names'] = array(
|
||||
$form['role_names'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => $role_names,
|
||||
);
|
||||
];
|
||||
// Render role/permission overview:
|
||||
$hide_descriptions = system_admin_compact_mode();
|
||||
|
||||
$form['system_compact_link'] = array(
|
||||
$form['system_compact_link'] = [
|
||||
'#id' => FALSE,
|
||||
'#type' => 'system_compact_link',
|
||||
);
|
||||
];
|
||||
|
||||
$form['permissions'] = array(
|
||||
$form['permissions'] = [
|
||||
'#type' => 'table',
|
||||
'#header' => array($this->t('Permission')),
|
||||
'#header' => [$this->t('Permission')],
|
||||
'#id' => 'permissions',
|
||||
'#attributes' => ['class' => ['permissions', 'js-permissions']],
|
||||
'#sticky' => TRUE,
|
||||
);
|
||||
];
|
||||
foreach ($role_names as $name) {
|
||||
$form['permissions']['#header'][] = array(
|
||||
$form['permissions']['#header'][] = [
|
||||
'data' => $name,
|
||||
'class' => array('checkbox'),
|
||||
);
|
||||
'class' => ['checkbox'],
|
||||
];
|
||||
}
|
||||
|
||||
$permissions = $this->permissionHandler->getPermissions();
|
||||
$permissions_by_provider = array();
|
||||
$permissions_by_provider = [];
|
||||
foreach ($permissions as $permission_name => $permission) {
|
||||
$permissions_by_provider[$permission['provider']][$permission_name] = $permission;
|
||||
}
|
||||
|
||||
foreach ($permissions_by_provider as $provider => $permissions) {
|
||||
// Module name.
|
||||
$form['permissions'][$provider] = array(array(
|
||||
'#wrapper_attributes' => array(
|
||||
$form['permissions'][$provider] = [[
|
||||
'#wrapper_attributes' => [
|
||||
'colspan' => count($role_names) + 1,
|
||||
'class' => array('module'),
|
||||
'class' => ['module'],
|
||||
'id' => 'module-' . $provider,
|
||||
),
|
||||
],
|
||||
'#markup' => $this->moduleHandler->getName($provider),
|
||||
));
|
||||
]];
|
||||
foreach ($permissions as $perm => $perm_item) {
|
||||
// Fill in default values for the permission.
|
||||
$perm_item += array(
|
||||
$perm_item += [
|
||||
'description' => '',
|
||||
'restrict access' => FALSE,
|
||||
'warning' => !empty($perm_item['restrict access']) ? $this->t('Warning: Give to trusted roles only; this permission has security implications.') : '',
|
||||
);
|
||||
$form['permissions'][$perm]['description'] = array(
|
||||
];
|
||||
$form['permissions'][$perm]['description'] = [
|
||||
'#type' => 'inline_template',
|
||||
'#template' => '<div class="permission"><span class="title">{{ title }}</span>{% if description or warning %}<div class="description">{% if warning %}<em class="permission-warning">{{ warning }}</em> {% endif %}{{ description }}</div>{% endif %}</div>',
|
||||
'#context' => array(
|
||||
'#context' => [
|
||||
'title' => $perm_item['title'],
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
// Show the permission description.
|
||||
if (!$hide_descriptions) {
|
||||
$form['permissions'][$perm]['description']['#context']['description'] = $perm_item['description'];
|
||||
$form['permissions'][$perm]['description']['#context']['warning'] = $perm_item['warning'];
|
||||
}
|
||||
foreach ($role_names as $rid => $name) {
|
||||
$form['permissions'][$perm][$rid] = array(
|
||||
$form['permissions'][$perm][$rid] = [
|
||||
'#title' => $name . ': ' . $perm_item['title'],
|
||||
'#title_display' => 'invisible',
|
||||
'#wrapper_attributes' => array(
|
||||
'class' => array('checkbox'),
|
||||
),
|
||||
'#wrapper_attributes' => [
|
||||
'class' => ['checkbox'],
|
||||
],
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => in_array($perm, $role_permissions[$rid]) ? 1 : 0,
|
||||
'#attributes' => array('class' => array('rid-' . $rid, 'js-rid-' . $rid)),
|
||||
'#parents' => array($rid, $perm),
|
||||
);
|
||||
'#attributes' => ['class' => ['rid-' . $rid, 'js-rid-' . $rid]],
|
||||
'#parents' => [$rid, $perm],
|
||||
];
|
||||
// Show a column of disabled but checked checkboxes.
|
||||
if ($admin_roles[$rid]) {
|
||||
$form['permissions'][$perm][$rid]['#disabled'] = TRUE;
|
||||
|
@ -177,12 +177,12 @@ class UserPermissionsForm extends FormBase {
|
|||
}
|
||||
}
|
||||
|
||||
$form['actions'] = array('#type' => 'actions');
|
||||
$form['actions']['submit'] = array(
|
||||
$form['actions'] = ['#type' => 'actions'];
|
||||
$form['actions']['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Save permissions'),
|
||||
'#button_type' => 'primary',
|
||||
);
|
||||
];
|
||||
|
||||
$form['#attached']['library'][] = 'user/drupal.user.permissions';
|
||||
|
||||
|
@ -192,7 +192,7 @@ class UserPermissionsForm extends FormBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
foreach ($form_state->getValue('role_names') as $role_name => $name) {
|
||||
user_role_change_permissions($role_name, (array) $form_state->getValue($role_name));
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ class UserPermissionsRoleSpecificForm extends UserPermissionsForm {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getRoles() {
|
||||
return array($this->userRole->id() => $this->userRole);
|
||||
return [$this->userRole->id() => $this->userRole];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -136,8 +136,8 @@ class PermissionHandler implements PermissionHandlerInterface {
|
|||
* - provider: The provider of the permission.
|
||||
*/
|
||||
protected function buildPermissionsYaml() {
|
||||
$all_permissions = array();
|
||||
$all_callback_permissions = array();
|
||||
$all_permissions = [];
|
||||
$all_callback_permissions = [];
|
||||
|
||||
foreach ($this->getYamlDiscovery()->findAll() as $provider => $permissions) {
|
||||
// The top-level 'permissions_callback' is a list of methods in controller
|
||||
|
@ -151,15 +151,15 @@ class PermissionHandler implements PermissionHandlerInterface {
|
|||
// defaults can then get processed below.
|
||||
foreach ($callback_permissions as $name => $callback_permission) {
|
||||
if (!is_array($callback_permission)) {
|
||||
$callback_permission = array(
|
||||
$callback_permission = [
|
||||
'title' => $callback_permission,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
$callback_permission += array(
|
||||
$callback_permission += [
|
||||
'description' => NULL,
|
||||
'provider' => $provider,
|
||||
);
|
||||
];
|
||||
|
||||
$all_callback_permissions[$name] = $callback_permission;
|
||||
}
|
||||
|
@ -171,9 +171,9 @@ class PermissionHandler implements PermissionHandlerInterface {
|
|||
|
||||
foreach ($permissions as &$permission) {
|
||||
if (!is_array($permission)) {
|
||||
$permission = array(
|
||||
$permission = [
|
||||
'title' => $permission,
|
||||
);
|
||||
];
|
||||
}
|
||||
$permission['title'] = $this->t($permission['title']);
|
||||
$permission['description'] = isset($permission['description']) ? $this->t($permission['description']) : NULL;
|
||||
|
@ -198,7 +198,7 @@ class PermissionHandler implements PermissionHandlerInterface {
|
|||
* - description: The description of the permission, defaults to NULL.
|
||||
* - provider: The provider of the permission.
|
||||
*/
|
||||
protected function sortPermissions(array $all_permissions = array()) {
|
||||
protected function sortPermissions(array $all_permissions = []) {
|
||||
// Get a list of all the modules providing permissions and sort by
|
||||
// display name.
|
||||
$modules = $this->getModuleNames();
|
||||
|
@ -221,7 +221,7 @@ class PermissionHandler implements PermissionHandlerInterface {
|
|||
* Returns the human readable names of all modules keyed by machine name.
|
||||
*/
|
||||
protected function getModuleNames() {
|
||||
$modules = array();
|
||||
$modules = [];
|
||||
foreach (array_keys($this->moduleHandler->getModuleList()) as $module) {
|
||||
$modules[$module] = $this->moduleHandler->getName($module);
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ class CancelUser extends ActionBase implements ContainerFactoryPluginInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function execute($object = NULL) {
|
||||
$this->executeMultiple(array($object));
|
||||
$this->executeMultiple([$object]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -49,9 +49,9 @@ abstract class ChangeUserRoleBase extends ConfigurableActionBase implements Cont
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function defaultConfiguration() {
|
||||
return array(
|
||||
return [
|
||||
'rid' => '',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -60,13 +60,13 @@ abstract class ChangeUserRoleBase extends ConfigurableActionBase implements Cont
|
|||
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
|
||||
$roles = user_role_names(TRUE);
|
||||
unset($roles[RoleInterface::AUTHENTICATED_ID]);
|
||||
$form['rid'] = array(
|
||||
$form['rid'] = [
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Role'),
|
||||
'#options' => $roles,
|
||||
'#default_value' => $this->configuration['rid'],
|
||||
'#required' => TRUE,
|
||||
);
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@ class UserLoginBlock extends BlockBase implements ContainerFactoryPluginInterfac
|
|||
*/
|
||||
protected function blockAccess(AccountInterface $account) {
|
||||
$route_name = $this->routeMatch->getRouteName();
|
||||
if ($account->isAnonymous() && !in_array($route_name, array('user.login', 'user.logout'))) {
|
||||
if ($account->isAnonymous() && !in_array($route_name, ['user.login', 'user.logout'])) {
|
||||
return AccessResult::allowed()
|
||||
->addCacheContexts(['route.name', 'user.roles:anonymous']);
|
||||
}
|
||||
|
@ -96,28 +96,36 @@ class UserLoginBlock extends BlockBase implements ContainerFactoryPluginInterfac
|
|||
$form['pass']['#size'] = 15;
|
||||
$form['#action'] = $this->url('<current>', [], ['query' => $this->getDestinationArray(), 'external' => FALSE]);
|
||||
// Build action links.
|
||||
$items = array();
|
||||
$items = [];
|
||||
if (\Drupal::config('user.settings')->get('register') != USER_REGISTER_ADMINISTRATORS_ONLY) {
|
||||
$items['create_account'] = \Drupal::l($this->t('Create new account'), new Url('user.register', array(), array(
|
||||
'attributes' => array(
|
||||
'title' => $this->t('Create a new user account.'),
|
||||
'class' => array('create-account-link'),
|
||||
),
|
||||
)));
|
||||
$items['create_account'] = [
|
||||
'#type' => 'link',
|
||||
'#title' => $this->t('Create new account'),
|
||||
'#url' => Url::fromRoute('user.register', [], [
|
||||
'attributes' => [
|
||||
'title' => $this->t('Create a new user account.'),
|
||||
'class' => ['create-account-link'],
|
||||
],
|
||||
]),
|
||||
];
|
||||
}
|
||||
$items['request_password'] = \Drupal::l($this->t('Reset your password'), new Url('user.pass', array(), array(
|
||||
'attributes' => array(
|
||||
'title' => $this->t('Send password reset instructions via email.'),
|
||||
'class' => array('request-password-link'),
|
||||
),
|
||||
)));
|
||||
return array(
|
||||
$items['request_password'] = [
|
||||
'#type' => 'link',
|
||||
'#title' => $this->t('Reset your password'),
|
||||
'#url' => Url::fromRoute('user.pass', [], [
|
||||
'attributes' => [
|
||||
'title' => $this->t('Send password reset instructions via email.'),
|
||||
'class' => ['request-password-link'],
|
||||
],
|
||||
]),
|
||||
];
|
||||
return [
|
||||
'user_login_form' => $form,
|
||||
'user_links' => array(
|
||||
'user_links' => [
|
||||
'#theme' => 'item_list',
|
||||
'#items' => $items,
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,13 +22,13 @@ class UserRole extends ConditionPluginBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
|
||||
$form['roles'] = array(
|
||||
$form['roles'] = [
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => $this->t('When the user has the following roles'),
|
||||
'#default_value' => $this->configuration['roles'],
|
||||
'#options' => array_map('\Drupal\Component\Utility\Html::escape', user_role_names()),
|
||||
'#description' => $this->t('If you select no roles, the condition will evaluate to TRUE for all users.'),
|
||||
);
|
||||
];
|
||||
return parent::buildConfigurationForm($form, $form_state);
|
||||
}
|
||||
|
||||
|
@ -36,9 +36,9 @@ class UserRole extends ConditionPluginBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function defaultConfiguration() {
|
||||
return array(
|
||||
'roles' => array(),
|
||||
) + parent::defaultConfiguration();
|
||||
return [
|
||||
'roles' => [],
|
||||
] + parent::defaultConfiguration();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -62,10 +62,10 @@ class UserRole extends ConditionPluginBase {
|
|||
$roles = reset($roles);
|
||||
}
|
||||
if (!empty($this->configuration['negate'])) {
|
||||
return $this->t('The user is not a member of @roles', array('@roles' => $roles));
|
||||
return $this->t('The user is not a member of @roles', ['@roles' => $roles]);
|
||||
}
|
||||
else {
|
||||
return $this->t('The user is a member of @roles', array('@roles' => $roles));
|
||||
return $this->t('The user is a member of @roles', ['@roles' => $roles]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -86,51 +86,51 @@ class UserSelection extends DefaultSelection {
|
|||
$selection_handler_settings = $this->configuration['handler_settings'];
|
||||
|
||||
// Merge in default values.
|
||||
$selection_handler_settings += array(
|
||||
'filter' => array(
|
||||
$selection_handler_settings += [
|
||||
'filter' => [
|
||||
'type' => '_none',
|
||||
),
|
||||
],
|
||||
'include_anonymous' => TRUE,
|
||||
);
|
||||
];
|
||||
|
||||
$form['include_anonymous'] = array(
|
||||
$form['include_anonymous'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Include the anonymous user.'),
|
||||
'#default_value' => $selection_handler_settings['include_anonymous'],
|
||||
);
|
||||
];
|
||||
|
||||
// Add user specific filter options.
|
||||
$form['filter']['type'] = array(
|
||||
$form['filter']['type'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Filter by'),
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
'_none' => $this->t('- None -'),
|
||||
'role' => $this->t('User role'),
|
||||
),
|
||||
],
|
||||
'#ajax' => TRUE,
|
||||
'#limit_validation_errors' => array(),
|
||||
'#limit_validation_errors' => [],
|
||||
'#default_value' => $selection_handler_settings['filter']['type'],
|
||||
);
|
||||
];
|
||||
|
||||
$form['filter']['settings'] = array(
|
||||
$form['filter']['settings'] = [
|
||||
'#type' => 'container',
|
||||
'#attributes' => array('class' => array('entity_reference-settings')),
|
||||
'#process' => array(array('\Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem', 'formProcessMergeParent')),
|
||||
);
|
||||
'#attributes' => ['class' => ['entity_reference-settings']],
|
||||
'#process' => [['\Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem', 'formProcessMergeParent']],
|
||||
];
|
||||
|
||||
if ($selection_handler_settings['filter']['type'] == 'role') {
|
||||
// Merge in default values.
|
||||
$selection_handler_settings['filter'] += array(
|
||||
$selection_handler_settings['filter'] += [
|
||||
'role' => NULL,
|
||||
);
|
||||
];
|
||||
|
||||
$form['filter']['settings']['role'] = array(
|
||||
$form['filter']['settings']['role'] = [
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => $this->t('Restrict to the selected roles'),
|
||||
'#required' => TRUE,
|
||||
'#options' => array_diff_key(user_role_names(TRUE), array(RoleInterface::AUTHENTICATED_ID => RoleInterface::AUTHENTICATED_ID)),
|
||||
'#options' => array_diff_key(user_role_names(TRUE), [RoleInterface::AUTHENTICATED_ID => RoleInterface::AUTHENTICATED_ID]),
|
||||
'#default_value' => $selection_handler_settings['filter']['role'],
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
$form += parent::buildConfigurationForm($form, $form_state);
|
||||
|
@ -239,7 +239,7 @@ class UserSelection extends DefaultSelection {
|
|||
$value_part->condition('anonymous_name', $condition['value'], $condition['operator']);
|
||||
$value_part->compile($this->connection, $query);
|
||||
$or->condition(db_and()
|
||||
->where(str_replace('anonymous_name', ':anonymous_name', (string) $value_part), $value_part->arguments() + array(':anonymous_name' => \Drupal::config('user.settings')->get('anonymous')))
|
||||
->where(str_replace('anonymous_name', ':anonymous_name', (string) $value_part), $value_part->arguments() + [':anonymous_name' => \Drupal::config('user.settings')->get('anonymous')])
|
||||
->condition('base_table.uid', 0)
|
||||
);
|
||||
$query->condition($or);
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Drupal\user\Plugin\Field\FieldFormatter;
|
||||
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Field\FieldDefinitionInterface;
|
||||
use Drupal\Core\Field\FieldItemListInterface;
|
||||
|
@ -26,18 +25,18 @@ class AuthorFormatter extends EntityReferenceFormatterBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||
$elements = array();
|
||||
$elements = [];
|
||||
|
||||
foreach ($this->getEntitiesToView($items, $langcode) as $delta => $entity) {
|
||||
/** @var $referenced_user \Drupal\user\UserInterface */
|
||||
$elements[$delta] = array(
|
||||
$elements[$delta] = [
|
||||
'#theme' => 'username',
|
||||
'#account' => $entity,
|
||||
'#link_options' => array('attributes' => array('rel' => 'author')),
|
||||
'#cache' => array(
|
||||
'#link_options' => ['attributes' => ['rel' => 'author']],
|
||||
'#cache' => [
|
||||
'tags' => $entity->getCacheTags(),
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
return $elements;
|
||||
|
@ -54,9 +53,7 @@ class AuthorFormatter extends EntityReferenceFormatterBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function checkAccess(EntityInterface $entity) {
|
||||
// Always allow an entity author's username to be read, even if the current
|
||||
// user does not have permission to view the entity author's profile.
|
||||
return AccessResult::allowed();
|
||||
return $entity->access('view label', NULL, TRUE);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -104,7 +104,7 @@ class UserSearch extends SearchPluginBase implements AccessibleInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function execute() {
|
||||
$results = array();
|
||||
$results = [];
|
||||
if (!$this->isSearchExecutable()) {
|
||||
return $results;
|
||||
}
|
||||
|
@ -120,12 +120,12 @@ class UserSearch extends SearchPluginBase implements AccessibleInterface {
|
|||
$query = $this->database
|
||||
->select('users_field_data', 'users')
|
||||
->extend('Drupal\Core\Database\Query\PagerSelectExtender');
|
||||
$query->fields('users', array('uid'));
|
||||
$query->fields('users', ['uid']);
|
||||
$query->condition('default_langcode', 1);
|
||||
if ($this->currentUser->hasPermission('administer users')) {
|
||||
// Administrators can also search in the otherwise private email field,
|
||||
// and they don't need to be restricted to only active users.
|
||||
$query->fields('users', array('mail'));
|
||||
$query->fields('users', ['mail']);
|
||||
$query->condition($query->orConditionGroup()
|
||||
->condition('name', '%' . $keys . '%', 'LIKE')
|
||||
->condition('mail', '%' . $keys . '%', 'LIKE')
|
||||
|
@ -144,10 +144,10 @@ class UserSearch extends SearchPluginBase implements AccessibleInterface {
|
|||
$accounts = $this->entityManager->getStorage('user')->loadMultiple($uids);
|
||||
|
||||
foreach ($accounts as $account) {
|
||||
$result = array(
|
||||
$result = [
|
||||
'title' => $account->getDisplayName(),
|
||||
'link' => $account->url('canonical', array('absolute' => TRUE)),
|
||||
);
|
||||
'link' => $account->url('canonical', ['absolute' => TRUE]),
|
||||
];
|
||||
if ($this->currentUser->hasPermission('administer users')) {
|
||||
$result['title'] .= ' (' . $account->getEmail() . ')';
|
||||
}
|
||||
|
@ -162,13 +162,13 @@ class UserSearch extends SearchPluginBase implements AccessibleInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getHelp() {
|
||||
$help = array('list' => array(
|
||||
$help = ['list' => [
|
||||
'#theme' => 'item_list',
|
||||
'#items' => array(
|
||||
'#items' => [
|
||||
$this->t('User search looks for user names and partial user names. Example: mar would match usernames mar, delmar, and maryjane.'),
|
||||
$this->t('You can use * as a wildcard within your keyword. Example: m*r would match user names mar, delmar, and elementary.'),
|
||||
),
|
||||
));
|
||||
],
|
||||
]];
|
||||
|
||||
return $help;
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ class ProtectedUserFieldConstraintValidator extends ConstraintValidator implemen
|
|||
$changed = $items->getValue() != $account_unchanged->get($field->getName())->getValue();
|
||||
}
|
||||
if ($changed && (!$account->checkExistingPassword($account_unchanged))) {
|
||||
$this->context->addViolation($constraint->message, array('%name' => $field->getLabel()));
|
||||
$this->context->addViolation($constraint->message, ['%name' => $field->getLabel()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,6 @@
|
|||
namespace Drupal\user\Plugin\Validation\Constraint;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidatorInterface;
|
||||
use Symfony\Component\Validator\ExecutionContextInterface;
|
||||
|
||||
/**
|
||||
* Checks if the user's email address is provided if required.
|
||||
|
@ -18,7 +16,7 @@ use Symfony\Component\Validator\ExecutionContextInterface;
|
|||
* label = @Translation("User email required", context = "Validation")
|
||||
* )
|
||||
*/
|
||||
class UserMailRequired extends Constraint implements ConstraintValidatorInterface {
|
||||
class UserMailRequired extends Constraint {
|
||||
|
||||
/**
|
||||
* Violation message. Use the same message as FormValidator.
|
||||
|
@ -30,45 +28,4 @@ class UserMailRequired extends Constraint implements ConstraintValidatorInterfac
|
|||
*/
|
||||
public $message = '@name field is required.';
|
||||
|
||||
/**
|
||||
* @var \Symfony\Component\Validator\ExecutionContextInterface
|
||||
*/
|
||||
protected $context;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function initialize(ExecutionContextInterface $context) {
|
||||
$this->context = $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function validatedBy() {
|
||||
return get_class($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function validate($items, Constraint $constraint) {
|
||||
/** @var \Drupal\Core\Field\FieldItemListInterface $items */
|
||||
/** @var \Drupal\user\UserInterface $account */
|
||||
$account = $items->getEntity();
|
||||
$existing_value = NULL;
|
||||
if ($account->id()) {
|
||||
$account_unchanged = \Drupal::entityManager()
|
||||
->getStorage('user')
|
||||
->loadUnchanged($account->id());
|
||||
$existing_value = $account_unchanged->getEmail();
|
||||
}
|
||||
|
||||
$required = !(!$existing_value && \Drupal::currentUser()->hasPermission('administer users'));
|
||||
|
||||
if ($required && (!isset($items) || $items->isEmpty())) {
|
||||
$this->context->addViolation($this->message, ['@name' => $account->getFieldDefinition('mail')->getLabel()]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\user\Plugin\Validation\Constraint;
|
||||
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
|
||||
/**
|
||||
* Checks if the user's email address is provided if required.
|
||||
*
|
||||
* The user mail field is NOT required if account originally had no mail set
|
||||
* and the user performing the edit has 'administer users' permission.
|
||||
* This allows users without email address to be edited and deleted.
|
||||
*/
|
||||
class UserMailRequiredValidator extends ConstraintValidator {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function validate($items, Constraint $constraint) {
|
||||
/** @var \Drupal\Core\Field\FieldItemListInterface $items */
|
||||
/** @var \Drupal\user\UserInterface $account */
|
||||
$account = $items->getEntity();
|
||||
$existing_value = NULL;
|
||||
if ($account->id()) {
|
||||
$account_unchanged = \Drupal::entityManager()
|
||||
->getStorage('user')
|
||||
->loadUnchanged($account->id());
|
||||
$existing_value = $account_unchanged->getEmail();
|
||||
}
|
||||
|
||||
$required = !(!$existing_value && \Drupal::currentUser()->hasPermission('administer users'));
|
||||
|
||||
if ($required && (!isset($items) || $items->isEmpty())) {
|
||||
$this->context->addViolation($constraint->message, ['@name' => $account->getFieldDefinition('mail')->getLabel()]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -54,7 +54,7 @@ class UserNameConstraintValidator extends ConstraintValidator {
|
|||
$this->context->addViolation($constraint->illegalMessage);
|
||||
}
|
||||
if (Unicode::strlen($name) > USERNAME_MAX_LENGTH) {
|
||||
$this->context->addViolation($constraint->tooLongMessage, array('%name' => $name, '%max' => USERNAME_MAX_LENGTH));
|
||||
$this->context->addViolation($constraint->tooLongMessage, ['%name' => $name, '%max' => USERNAME_MAX_LENGTH]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ class EntityUser extends EntityContentBase {
|
|||
* {@inheritdoc}
|
||||
* @throws \Drupal\migrate\MigrateException
|
||||
*/
|
||||
public function import(Row $row, array $old_destination_id_values = array()) {
|
||||
public function import(Row $row, array $old_destination_id_values = []) {
|
||||
// Do not overwrite the root account password.
|
||||
if ($row->getDestinationProperty('uid') == 1) {
|
||||
$row->removeDestinationProperty('pass');
|
||||
|
@ -88,7 +88,7 @@ class EntityUser extends EntityContentBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function save(ContentEntityInterface $entity, array $old_destination_id_values = array()) {
|
||||
protected function save(ContentEntityInterface $entity, array $old_destination_id_values = []) {
|
||||
// Do not overwrite the root account password.
|
||||
if ($entity->id() != 1) {
|
||||
// Set the pre_hashed password so that the PasswordItem field does not hash
|
||||
|
|
|
@ -56,7 +56,7 @@ class UserData extends DestinationBase implements ContainerFactoryPluginInterfac
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function import(Row $row, array $old_destination_id_values = array()) {
|
||||
public function import(Row $row, array $old_destination_id_values = []) {
|
||||
$uid = $row->getDestinationProperty('uid');
|
||||
$module = $row->getDestinationProperty('module');
|
||||
$key = $row->getDestinationProperty('key');
|
||||
|
|
|
@ -21,7 +21,7 @@ class ConvertTokens extends ProcessPluginBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||
$tokens = array(
|
||||
$tokens = [
|
||||
'!site' => '[site:name]',
|
||||
'!username' => '[user:name]',
|
||||
'!mailto' => '[user:mail]',
|
||||
|
@ -32,7 +32,7 @@ class ConvertTokens extends ProcessPluginBase {
|
|||
'!uri' => '[site:url]',
|
||||
'!date' => '[date:medium]',
|
||||
'!password' => '',
|
||||
);
|
||||
];
|
||||
|
||||
// Given that our source is a database column that could hold a NULL
|
||||
// value, sometimes that filters down to here. str_replace() cannot
|
||||
|
|
|
@ -17,7 +17,7 @@ class ProfileFieldSettings extends ProcessPluginBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function transform($type, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||
$settings = array();
|
||||
$settings = [];
|
||||
switch ($type) {
|
||||
case 'date':
|
||||
$settings['datetime_type'] = 'date';
|
||||
|
|
|
@ -22,10 +22,10 @@ class UserUpdate8002 extends ProcessPluginBase {
|
|||
*/
|
||||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||
$rid = $row->getSourceProperty('rid');
|
||||
$map = array(
|
||||
$map = [
|
||||
1 => 'anonymous',
|
||||
2 => 'authenticated',
|
||||
);
|
||||
];
|
||||
return isset($map[$rid]) ? $map[$rid] : $value;
|
||||
}
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ class ProfileField extends DrupalSqlBase {
|
|||
// D6 profile checkboxes values are always 0 or 1 (with no labels), so we
|
||||
// need to create two label-less options that will get 0 and 1 for their
|
||||
// keys.
|
||||
$row->setSourceProperty('options', array(NULL, NULL));
|
||||
$row->setSourceProperty('options', [NULL, NULL]);
|
||||
}
|
||||
|
||||
return parent::prepareRow($row);
|
||||
|
@ -80,7 +80,7 @@ class ProfileField extends DrupalSqlBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
return [
|
||||
'fid' => $this->t('Primary Key: Unique profile field ID.'),
|
||||
'title' => $this->t('Title of the field shown to the end user.'),
|
||||
'name' => $this->t('Internal name of the field used in the form HTML and URLs.'),
|
||||
|
@ -94,7 +94,7 @@ class ProfileField extends DrupalSqlBase {
|
|||
'visibility' => $this->t('The level of visibility for the field. (0 = hidden, 1 = private, 2 = public on profile but not member list pages, 3 = public on profile and list pages)'),
|
||||
'autocomplete' => $this->t('Whether form auto-completion is enabled. (0 = disabled, 1 = enabled)'),
|
||||
'options' => $this->t('List of options to be used in a list selection field.'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,24 +22,24 @@ class UserPictureInstance extends DrupalSqlBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function initializeIterator() {
|
||||
return new \ArrayIterator(array(
|
||||
array(
|
||||
return new \ArrayIterator([
|
||||
[
|
||||
'id' => '',
|
||||
'file_directory' => $this->variableGet('user_picture_path', 'pictures'),
|
||||
'max_filesize' => $this->variableGet('user_picture_file_size', '30') . 'KB',
|
||||
'max_resolution' => $this->variableGet('user_picture_dimensions', '85x85'),
|
||||
)));
|
||||
]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
return [
|
||||
'file_directory' => 'The directory to store images..',
|
||||
'max_filesize' => 'The maximum allowed file size in KBs.',
|
||||
'max_resolution' => "The maximum resolution.",
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -21,7 +21,7 @@ class ProfileFieldValues extends DrupalSqlBase {
|
|||
public function query() {
|
||||
$query = $this->select('profile_values', 'pv')
|
||||
->distinct()
|
||||
->fields('pv', array('uid'));
|
||||
->fields('pv', ['uid']);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
@ -32,9 +32,9 @@ class ProfileFieldValues extends DrupalSqlBase {
|
|||
public function prepareRow(Row $row) {
|
||||
// Find profile values for this row.
|
||||
$query = $this->select('profile_values', 'pv')
|
||||
->fields('pv', array('fid', 'value'));
|
||||
->fields('pv', ['fid', 'value']);
|
||||
$query->leftJoin('profile_fields', 'pf', 'pf.fid=pv.fid');
|
||||
$query->fields('pf', array('name', 'type'));
|
||||
$query->fields('pf', ['name', 'type']);
|
||||
$query->condition('uid', $row->getSourceProperty('uid'));
|
||||
$results = $query->execute();
|
||||
|
||||
|
@ -43,14 +43,14 @@ class ProfileFieldValues extends DrupalSqlBase {
|
|||
if ($profile_value['type'] == 'date') {
|
||||
$date = unserialize($profile_value['value']);
|
||||
$date = date('Y-m-d', mktime(0, 0, 0, $date['month'], $date['day'], $date['year']));
|
||||
$row->setSourceProperty($profile_value['name'], array('value' => $date));
|
||||
$row->setSourceProperty($profile_value['name'], ['value' => $date]);
|
||||
}
|
||||
elseif ($profile_value['type'] == 'list') {
|
||||
// Explode by newline and comma.
|
||||
$row->setSourceProperty($profile_value['name'], preg_split("/[\r\n,]+/", $profile_value['value']));
|
||||
}
|
||||
else {
|
||||
$row->setSourceProperty($profile_value['name'], array($profile_value['value']));
|
||||
$row->setSourceProperty($profile_value['name'], [$profile_value['value']]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,16 +61,16 @@ class ProfileFieldValues extends DrupalSqlBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
$fields = array(
|
||||
$fields = [
|
||||
'fid' => $this->t('Unique profile field ID.'),
|
||||
'uid' => $this->t('The user Id.'),
|
||||
'value' => $this->t('The value for this field.'),
|
||||
);
|
||||
];
|
||||
|
||||
$query = $this->select('profile_values', 'pv')
|
||||
->fields('pv', array('fid', 'value'));
|
||||
->fields('pv', ['fid', 'value']);
|
||||
$query->leftJoin('profile_fields', 'pf', 'pf.fid=pv.fid');
|
||||
$query->fields('pf', array('name', 'title'));
|
||||
$query->fields('pf', ['name', 'title']);
|
||||
$results = $query->execute();
|
||||
foreach ($results as $profile) {
|
||||
$fields[$profile['name']] = $this->t($profile['title']);
|
||||
|
@ -83,12 +83,12 @@ class ProfileFieldValues extends DrupalSqlBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
return array(
|
||||
'uid' => array(
|
||||
return [
|
||||
'uid' => [
|
||||
'type' => 'integer',
|
||||
'alias' => 'pv',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,14 +19,14 @@ class Role extends DrupalSqlBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $filterPermissions = array();
|
||||
protected $filterPermissions = [];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
$query = $this->select('role', 'r')
|
||||
->fields('r', array('rid', 'name'))
|
||||
->fields('r', ['rid', 'name'])
|
||||
->orderBy('r.rid');
|
||||
return $query;
|
||||
}
|
||||
|
@ -35,10 +35,10 @@ class Role extends DrupalSqlBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
return [
|
||||
'rid' => $this->t('Role ID.'),
|
||||
'name' => $this->t('The name of the user role.'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -46,7 +46,7 @@ class Role extends DrupalSqlBase {
|
|||
*/
|
||||
protected function initializeIterator() {
|
||||
$filter_roles = $this->select('filter_formats', 'f')
|
||||
->fields('f', array('format', 'roles'))
|
||||
->fields('f', ['format', 'roles'])
|
||||
->execute()
|
||||
->fetchAllKeyed();
|
||||
foreach ($filter_roles as $format => $roles) {
|
||||
|
@ -65,7 +65,7 @@ class Role extends DrupalSqlBase {
|
|||
public function prepareRow(Row $row) {
|
||||
$rid = $row->getSourceProperty('rid');
|
||||
$permissions = $this->select('permission', 'p')
|
||||
->fields('p', array('perm'))
|
||||
->fields('p', ['perm'])
|
||||
->condition('rid', $rid)
|
||||
->execute()
|
||||
->fetchField();
|
||||
|
|
|
@ -35,7 +35,7 @@ class User extends DrupalSqlBase {
|
|||
// Profile fields.
|
||||
if ($this->moduleExists('profile')) {
|
||||
$fields += $this->select('profile_fields', 'pf')
|
||||
->fields('pf', array('name', 'title'))
|
||||
->fields('pf', ['name', 'title'])
|
||||
->execute()
|
||||
->fetchAllKeyed();
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ class User extends DrupalSqlBase {
|
|||
public function prepareRow(Row $row) {
|
||||
// User roles.
|
||||
$roles = $this->select('users_roles', 'ur')
|
||||
->fields('ur', array('rid'))
|
||||
->fields('ur', ['rid'])
|
||||
->condition('ur.uid', $row->getSourceProperty('uid'))
|
||||
->execute()
|
||||
->fetchCol();
|
||||
|
@ -60,7 +60,7 @@ class User extends DrupalSqlBase {
|
|||
if ($row->hasSourceProperty('timezone_id') && $row->getSourceProperty('timezone_id')) {
|
||||
if ($this->getDatabase()->schema()->tableExists('event_timezones')) {
|
||||
$event_timezone = $this->select('event_timezones', 'e')
|
||||
->fields('e', array('name'))
|
||||
->fields('e', ['name'])
|
||||
->condition('e.timezone', $row->getSourceProperty('timezone_id'))
|
||||
->execute()
|
||||
->fetchField();
|
||||
|
@ -80,12 +80,12 @@ class User extends DrupalSqlBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
return array(
|
||||
'uid' => array(
|
||||
return [
|
||||
'uid' => [
|
||||
'type' => 'integer',
|
||||
'alias' => 'u',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -95,7 +95,7 @@ class User extends DrupalSqlBase {
|
|||
* Associative array having field name as key and description as value.
|
||||
*/
|
||||
protected function baseFields() {
|
||||
$fields = array(
|
||||
$fields = [
|
||||
'uid' => $this->t('User ID'),
|
||||
'name' => $this->t('Username'),
|
||||
'pass' => $this->t('Password'),
|
||||
|
@ -112,7 +112,7 @@ class User extends DrupalSqlBase {
|
|||
'picture' => $this->t('Picture'),
|
||||
'init' => $this->t('Init'),
|
||||
'data' => $this->t('User data'),
|
||||
);
|
||||
];
|
||||
|
||||
// Possible field added by Date contributed module.
|
||||
// @see https://api.drupal.org/api/drupal/modules%21user%21user.install/function/user_update_7002/7
|
||||
|
|
|
@ -21,7 +21,7 @@ class UserPicture extends DrupalSqlBase {
|
|||
public function query() {
|
||||
$query = $this->select('users', 'u')
|
||||
->condition('picture', '', '<>')
|
||||
->fields('u', array('uid', 'access', 'picture'))
|
||||
->fields('u', ['uid', 'access', 'picture'])
|
||||
->orderBy('u.access');
|
||||
return $query;
|
||||
}
|
||||
|
@ -30,11 +30,11 @@ class UserPicture extends DrupalSqlBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
return [
|
||||
'uid' => 'Primary Key: Unique user ID.',
|
||||
'access' => 'Timestamp for previous time user accessed the site.',
|
||||
'picture' => "Path to the user's uploaded picture.",
|
||||
);
|
||||
];
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -34,7 +34,7 @@ class UserPictureFile extends DrupalSqlBase {
|
|||
public function query() {
|
||||
$query = $this->select('users', 'u')
|
||||
->condition('u.picture', '', '<>')
|
||||
->fields('u', array('uid', 'picture'));
|
||||
->fields('u', ['uid', 'picture']);
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
@ -62,10 +62,10 @@ class UserPictureFile extends DrupalSqlBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
return [
|
||||
'picture' => "Path to the user's uploaded picture.",
|
||||
'filename' => 'The picture filename.',
|
||||
);
|
||||
];
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -25,11 +25,11 @@ class Role extends DrupalSqlBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
return [
|
||||
'rid' => $this->t('Role ID.'),
|
||||
'name' => $this->t('The name of the user role.'),
|
||||
'weight' => $this->t('The weight of the role.'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -27,7 +27,7 @@ class User extends FieldableEntity {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
$fields = array(
|
||||
$fields = [
|
||||
'uid' => $this->t('User ID'),
|
||||
'name' => $this->t('Username'),
|
||||
'pass' => $this->t('Password'),
|
||||
|
@ -44,12 +44,12 @@ class User extends FieldableEntity {
|
|||
'init' => $this->t('Init'),
|
||||
'data' => $this->t('User data'),
|
||||
'roles' => $this->t('Roles'),
|
||||
);
|
||||
];
|
||||
|
||||
// Profile fields.
|
||||
if ($this->moduleExists('profile')) {
|
||||
$fields += $this->select('profile_fields', 'pf')
|
||||
->fields('pf', array('name', 'title'))
|
||||
->fields('pf', ['name', 'title'])
|
||||
->execute()
|
||||
->fetchAllKeyed();
|
||||
}
|
||||
|
@ -79,9 +79,9 @@ class User extends FieldableEntity {
|
|||
// ProfileFieldValues plugin.
|
||||
if ($this->getDatabase()->schema()->tableExists('profile_value')) {
|
||||
$query = $this->select('profile_value', 'pv')
|
||||
->fields('pv', array('fid', 'value'));
|
||||
->fields('pv', ['fid', 'value']);
|
||||
$query->leftJoin('profile_field', 'pf', 'pf.fid=pv.fid');
|
||||
$query->fields('pf', array('name', 'type'));
|
||||
$query->fields('pf', ['name', 'type']);
|
||||
$query->condition('uid', $row->getSourceProperty('uid'));
|
||||
$results = $query->execute();
|
||||
|
||||
|
@ -89,14 +89,14 @@ class User extends FieldableEntity {
|
|||
if ($profile_value['type'] == 'date') {
|
||||
$date = unserialize($profile_value['value']);
|
||||
$date = date('Y-m-d', mktime(0, 0, 0, $date['month'], $date['day'], $date['year']));
|
||||
$row->setSourceProperty($profile_value['name'], array('value' => $date));
|
||||
$row->setSourceProperty($profile_value['name'], ['value' => $date]);
|
||||
}
|
||||
elseif ($profile_value['type'] == 'list') {
|
||||
// Explode by newline and comma.
|
||||
$row->setSourceProperty($profile_value['name'], preg_split("/[\r\n,]+/", $profile_value['value']));
|
||||
}
|
||||
else {
|
||||
$row->setSourceProperty($profile_value['name'], array($profile_value['value']));
|
||||
$row->setSourceProperty($profile_value['name'], [$profile_value['value']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -108,12 +108,12 @@ class User extends FieldableEntity {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
return array(
|
||||
'uid' => array(
|
||||
return [
|
||||
'uid' => [
|
||||
'type' => 'integer',
|
||||
'alias' => 'u',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,190 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\user\Plugin\rest\resource;
|
||||
|
||||
use Drupal\Core\Config\ImmutableConfig;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\rest\ModifiedResourceResponse;
|
||||
use Drupal\rest\Plugin\ResourceBase;
|
||||
use Drupal\rest\Plugin\rest\resource\EntityResourceAccessTrait;
|
||||
use Drupal\rest\Plugin\rest\resource\EntityResourceValidationTrait;
|
||||
use Drupal\user\UserInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
|
||||
|
||||
/**
|
||||
* Represents user registration as a resource.
|
||||
*
|
||||
* @RestResource(
|
||||
* id = "user_registration",
|
||||
* label = @Translation("User registration"),
|
||||
* serialization_class = "Drupal\user\Entity\User",
|
||||
* uri_paths = {
|
||||
* "https://www.drupal.org/link-relations/create" = "/user/register",
|
||||
* },
|
||||
* )
|
||||
*/
|
||||
class UserRegistrationResource extends ResourceBase {
|
||||
|
||||
use EntityResourceValidationTrait;
|
||||
use EntityResourceAccessTrait;
|
||||
|
||||
/**
|
||||
* User settings config instance.
|
||||
*
|
||||
* @var \Drupal\Core\Config\ImmutableConfig
|
||||
*/
|
||||
protected $userSettings;
|
||||
|
||||
/**
|
||||
* The current user.
|
||||
*
|
||||
* @var \Drupal\Core\Session\AccountInterface
|
||||
*/
|
||||
protected $currentUser;
|
||||
|
||||
/**
|
||||
* Constructs a new UserRegistrationResource instance.
|
||||
*
|
||||
* @param array $configuration
|
||||
* A configuration array containing information about the plugin instance.
|
||||
* @param string $plugin_id
|
||||
* The plugin_id for the plugin instance.
|
||||
* @param mixed $plugin_definition
|
||||
* The plugin implementation definition.
|
||||
* @param array $serializer_formats
|
||||
* The available serialization formats.
|
||||
* @param \Psr\Log\LoggerInterface $logger
|
||||
* A logger instance.
|
||||
* @param \Drupal\Core\Config\ImmutableConfig $user_settings
|
||||
* A user settings config instance.
|
||||
* @param \Drupal\Core\Session\AccountInterface $current_user
|
||||
* The current user.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, array $serializer_formats, LoggerInterface $logger, ImmutableConfig $user_settings, AccountInterface $current_user) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition, $serializer_formats, $logger);
|
||||
$this->userSettings = $user_settings;
|
||||
$this->currentUser = $current_user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
|
||||
return new static(
|
||||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$container->getParameter('serializer.formats'),
|
||||
$container->get('logger.factory')->get('rest'),
|
||||
$container->get('config.factory')->get('user.settings'),
|
||||
$container->get('current_user')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Responds to user registration POST request.
|
||||
*
|
||||
* @param \Drupal\user\UserInterface $account
|
||||
* The user account entity.
|
||||
*
|
||||
* @return \Drupal\rest\ModifiedResourceResponse
|
||||
* The HTTP response object.
|
||||
*
|
||||
* @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
|
||||
* @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
|
||||
*/
|
||||
public function post(UserInterface $account = NULL) {
|
||||
$this->ensureAccountCanRegister($account);
|
||||
|
||||
// Only activate new users if visitors are allowed to register and no email
|
||||
// verification required.
|
||||
if ($this->userSettings->get('register') == USER_REGISTER_VISITORS && !$this->userSettings->get('verify_mail')) {
|
||||
$account->activate();
|
||||
}
|
||||
else {
|
||||
$account->block();
|
||||
}
|
||||
|
||||
$this->checkEditFieldAccess($account);
|
||||
|
||||
// Make sure that the user entity is valid (email and name are valid).
|
||||
$this->validate($account);
|
||||
|
||||
// Create the account.
|
||||
$account->save();
|
||||
|
||||
$this->sendEmailNotifications($account);
|
||||
|
||||
return new ModifiedResourceResponse($account, 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the account can be registered in this request.
|
||||
*
|
||||
* @param \Drupal\user\UserInterface $account
|
||||
* The user account to register.
|
||||
*/
|
||||
protected function ensureAccountCanRegister(UserInterface $account = NULL) {
|
||||
if ($account === NULL) {
|
||||
throw new BadRequestHttpException('No user account data for registration received.');
|
||||
}
|
||||
|
||||
// POSTed user accounts must not have an ID set, because we always want to
|
||||
// create new entities here.
|
||||
if (!$account->isNew()) {
|
||||
throw new BadRequestHttpException('An ID has been set and only new user accounts can be registered.');
|
||||
}
|
||||
|
||||
// Only allow anonymous users to register, authenticated users with the
|
||||
// necessary permissions can POST a new user to the "user" REST resource.
|
||||
// @see \Drupal\rest\Plugin\rest\resource\EntityResource
|
||||
if (!$this->currentUser->isAnonymous()) {
|
||||
throw new AccessDeniedHttpException('Only anonymous users can register a user.');
|
||||
}
|
||||
|
||||
// Verify that the current user can register a user account.
|
||||
if ($this->userSettings->get('register') == USER_REGISTER_ADMINISTRATORS_ONLY) {
|
||||
throw new AccessDeniedHttpException('You cannot register a new user account.');
|
||||
}
|
||||
|
||||
if (!$this->userSettings->get('verify_mail')) {
|
||||
if (empty($account->getPassword())) {
|
||||
// If no e-mail verification then the user must provide a password.
|
||||
throw new UnprocessableEntityHttpException('No password provided.');
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!empty($account->getPassword())) {
|
||||
// If e-mail verification required then a password cannot provided.
|
||||
// The password will be set when the user logs in.
|
||||
throw new UnprocessableEntityHttpException('A Password cannot be specified. It will be generated on login.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends email notifications if necessary for user that was registered.
|
||||
*
|
||||
* @param \Drupal\user\UserInterface $account
|
||||
* The user account.
|
||||
*/
|
||||
protected function sendEmailNotifications(UserInterface $account) {
|
||||
$approval_settings = $this->userSettings->get('register');
|
||||
// No e-mail verification is required. Activating the user.
|
||||
if ($approval_settings == USER_REGISTER_VISITORS) {
|
||||
if ($this->userSettings->get('verify_mail')) {
|
||||
// No administrator approval required.
|
||||
_user_mail_notify('register_no_approval_required', $account);
|
||||
}
|
||||
}
|
||||
// Administrator approval required.
|
||||
elseif ($approval_settings == USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL) {
|
||||
_user_mail_notify('register_pending_approval', $account);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -103,7 +103,7 @@ class Permission extends AccessPluginBase implements CacheableDependencyInterfac
|
|||
|
||||
protected function defineOptions() {
|
||||
$options = parent::defineOptions();
|
||||
$options['perm'] = array('default' => 'access content');
|
||||
$options['perm'] = ['default' => 'access content'];
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
@ -119,13 +119,13 @@ class Permission extends AccessPluginBase implements CacheableDependencyInterfac
|
|||
$perms[$display_name][$perm] = strip_tags($perm_item['title']);
|
||||
}
|
||||
|
||||
$form['perm'] = array(
|
||||
$form['perm'] = [
|
||||
'#type' => 'select',
|
||||
'#options' => $perms,
|
||||
'#title' => $this->t('Permission'),
|
||||
'#default_value' => $this->options['perm'],
|
||||
'#description' => $this->t('Only users with the selected permission flag will be able to access this display.'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -99,31 +99,31 @@ class Role extends AccessPluginBase implements CacheableDependencyInterface {
|
|||
|
||||
protected function defineOptions() {
|
||||
$options = parent::defineOptions();
|
||||
$options['role'] = array('default' => array());
|
||||
$options['role'] = ['default' => []];
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
|
||||
parent::buildOptionsForm($form, $form_state);
|
||||
$form['role'] = array(
|
||||
$form['role'] = [
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => $this->t('Role'),
|
||||
'#default_value' => $this->options['role'],
|
||||
'#options' => array_map('\Drupal\Component\Utility\Html::escape', user_role_names()),
|
||||
'#description' => $this->t('Only the checked roles will be able to access this display.'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
public function validateOptionsForm(&$form, FormStateInterface $form_state) {
|
||||
$role = $form_state->getValue(array('access_options', 'role'));
|
||||
$role = $form_state->getValue(['access_options', 'role']);
|
||||
$role = array_filter($role);
|
||||
|
||||
if (!$role) {
|
||||
$form_state->setError($form['role'], $this->t('You must select at least one role if type is "by role"'));
|
||||
}
|
||||
|
||||
$form_state->setValue(array('access_options', 'role'), $role);
|
||||
$form_state->setValue(['access_options', 'role'], $role);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -52,7 +52,7 @@ class RolesRid extends ManyToOne {
|
|||
*/
|
||||
public function titleQuery() {
|
||||
$entities = $this->roleStorage->loadMultiple($this->value);
|
||||
$titles = array();
|
||||
$titles = [];
|
||||
foreach ($entities as $entity) {
|
||||
$titles[] = $entity->label();
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ class User extends ArgumentDefaultPluginBase implements CacheableDependencyInter
|
|||
*/
|
||||
protected function defineOptions() {
|
||||
$options = parent::defineOptions();
|
||||
$options['user'] = array('default' => '');
|
||||
$options['user'] = ['default' => ''];
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
@ -73,11 +73,11 @@ class User extends ArgumentDefaultPluginBase implements CacheableDependencyInter
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
|
||||
$form['user'] = array(
|
||||
$form['user'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Also look for a node and use the node author'),
|
||||
'#default_value' => $this->options['user'],
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -38,8 +38,8 @@ class User extends Entity {
|
|||
*/
|
||||
protected function defineOptions() {
|
||||
$options = parent::defineOptions();
|
||||
$options['restrict_roles'] = array('default' => FALSE);
|
||||
$options['roles'] = array('default' => array());
|
||||
$options['restrict_roles'] = ['default' => FALSE];
|
||||
$options['roles'] = ['default' => []];
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
@ -51,30 +51,30 @@ class User extends Entity {
|
|||
parent::buildOptionsForm($form, $form_state);
|
||||
$sanitized_id = ArgumentPluginBase::encodeValidatorId($this->definition['id']);
|
||||
|
||||
$form['restrict_roles'] = array(
|
||||
$form['restrict_roles'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Restrict user based on role'),
|
||||
'#default_value' => $this->options['restrict_roles'],
|
||||
);
|
||||
];
|
||||
|
||||
$form['roles'] = array(
|
||||
$form['roles'] = [
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => $this->t('Restrict to the selected roles'),
|
||||
'#options' => array_map(array('\Drupal\Component\Utility\Html', 'escape'), user_role_names(TRUE)),
|
||||
'#options' => array_map(['\Drupal\Component\Utility\Html', 'escape'], user_role_names(TRUE)),
|
||||
'#default_value' => $this->options['roles'],
|
||||
'#description' => $this->t('If no roles are selected, users from any role will be allowed.'),
|
||||
'#states' => array(
|
||||
'visible' => array(
|
||||
':input[name="options[validate][options][' . $sanitized_id . '][restrict_roles]"]' => array('checked' => TRUE),
|
||||
),
|
||||
),
|
||||
);
|
||||
'#states' => [
|
||||
'visible' => [
|
||||
':input[name="options[validate][options][' . $sanitized_id . '][restrict_roles]"]' => ['checked' => TRUE],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitOptionsForm(&$form, FormStateInterface $form_state, &$options = array()) {
|
||||
public function submitOptionsForm(&$form, FormStateInterface $form_state, &$options = []) {
|
||||
// filter trash out of the options so we don't store giant unnecessary arrays
|
||||
$options['roles'] = array_filter($options['roles']);
|
||||
}
|
||||
|
|
|
@ -23,10 +23,10 @@ class UserName extends User {
|
|||
|
||||
$entity_type = $this->entityManager->getDefinition('user');
|
||||
|
||||
$form['multiple']['#options'] = array(
|
||||
0 => $this->t('Single name', array('%type' => $entity_type->getLabel())),
|
||||
1 => $this->t('One or more names separated by , or +', array('%type' => $entity_type->getLabel())),
|
||||
);
|
||||
$form['multiple']['#options'] = [
|
||||
0 => $this->t('Single name', ['%type' => $entity_type->getLabel()]),
|
||||
1 => $this->t('One or more names separated by , or +', ['%type' => $entity_type->getLabel()]),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -39,14 +39,14 @@ class UserName extends User {
|
|||
$names = array_filter(preg_split('/[,+ ]/', $argument));
|
||||
}
|
||||
elseif ($argument) {
|
||||
$names = array($argument);
|
||||
$names = [$argument];
|
||||
}
|
||||
// No specified argument should be invalid.
|
||||
else {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$accounts = $this->userStorage->loadByProperties(array('name' => $names));
|
||||
$accounts = $this->userStorage->loadByProperties(['name' => $names]);
|
||||
|
||||
// If there are no accounts, return FALSE now. As we will not enter the
|
||||
// loop below otherwise.
|
||||
|
|
|
@ -66,7 +66,7 @@ class Permissions extends PrerenderList {
|
|||
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
|
||||
parent::init($view, $display, $options);
|
||||
|
||||
$this->additional_fields['uid'] = array('table' => 'users_field_data', 'field' => 'uid');
|
||||
$this->additional_fields['uid'] = ['table' => 'users_field_data', 'field' => 'uid'];
|
||||
}
|
||||
|
||||
public function query() {
|
||||
|
@ -75,12 +75,11 @@ class Permissions extends PrerenderList {
|
|||
}
|
||||
|
||||
public function preRender(&$values) {
|
||||
$uids = array();
|
||||
$this->items = array();
|
||||
$this->items = [];
|
||||
|
||||
$permission_names = \Drupal::service('user.permissions')->getPermissions();
|
||||
|
||||
$rids = array();
|
||||
$rids = [];
|
||||
foreach ($values as $result) {
|
||||
$user_rids = $this->getEntity($result)->getRoles();
|
||||
$uid = $this->getValue($result);
|
||||
|
@ -100,15 +99,13 @@ class Permissions extends PrerenderList {
|
|||
}
|
||||
}
|
||||
|
||||
foreach ($uids as $uid) {
|
||||
if (isset($this->items[$uid])) {
|
||||
ksort($this->items[$uid]);
|
||||
}
|
||||
foreach ($this->items as &$permission) {
|
||||
ksort($permission);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function render_item($count, $item) {
|
||||
public function render_item($count, $item) {
|
||||
return $item['permission'];
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ class Roles extends PrerenderList {
|
|||
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
|
||||
parent::init($view, $display, $options);
|
||||
|
||||
$this->additional_fields['uid'] = array('table' => 'users_field_data', 'field' => 'uid');
|
||||
$this->additional_fields['uid'] = ['table' => 'users_field_data', 'field' => 'uid'];
|
||||
}
|
||||
|
||||
public function query() {
|
||||
|
@ -64,8 +64,8 @@ class Roles extends PrerenderList {
|
|||
}
|
||||
|
||||
public function preRender(&$values) {
|
||||
$uids = array();
|
||||
$this->items = array();
|
||||
$uids = [];
|
||||
$this->items = [];
|
||||
|
||||
foreach ($values as $result) {
|
||||
$uids[] = $this->getValue($result);
|
||||
|
@ -73,7 +73,7 @@ class Roles extends PrerenderList {
|
|||
|
||||
if ($uids) {
|
||||
$roles = user_roles();
|
||||
$result = $this->database->query('SELECT u.entity_id as uid, u.roles_target_id as rid FROM {user__roles} u WHERE u.entity_id IN ( :uids[] ) AND u.roles_target_id IN ( :rids[] )', array(':uids[]' => $uids, ':rids[]' => array_keys($roles)));
|
||||
$result = $this->database->query('SELECT u.entity_id as uid, u.roles_target_id as rid FROM {user__roles} u WHERE u.entity_id IN ( :uids[] ) AND u.roles_target_id IN ( :rids[] )', [':uids[]' => $uids, ':rids[]' => array_keys($roles)]);
|
||||
foreach ($result as $role) {
|
||||
$this->items[$role->uid][$role->rid]['role'] = $roles[$role->rid]->label();
|
||||
$this->items[$role->uid][$role->rid]['rid'] = $role->rid;
|
||||
|
@ -90,7 +90,7 @@ class Roles extends PrerenderList {
|
|||
}
|
||||
}
|
||||
|
||||
function render_item($count, $item) {
|
||||
public function render_item($count, $item) {
|
||||
return $item['role'];
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ class UserBulkForm extends BulkForm {
|
|||
foreach ($this->view->result as $row_index => $result) {
|
||||
$account = $result->_entity;
|
||||
if ($account instanceof UserInterface) {
|
||||
$form[$this->options['id']][$row_index]['#title'] = $this->t('Update the user %name', array('%name' => $account->label()));
|
||||
$form[$this->options['id']][$row_index]['#title'] = $this->t('Update the user %name', ['%name' => $account->label()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,8 +58,8 @@ class UserData extends FieldPluginBase {
|
|||
protected function defineOptions() {
|
||||
$options = parent::defineOptions();
|
||||
|
||||
$options['data_module'] = array('default' => '');
|
||||
$options['data_name'] = array('default' => '');
|
||||
$options['data_module'] = ['default' => ''];
|
||||
$options['data_name'] = ['default' => ''];
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
@ -71,25 +71,25 @@ class UserData extends FieldPluginBase {
|
|||
parent::buildOptionsForm($form, $form_state);
|
||||
|
||||
$modules = $this->moduleHandler->getModuleList();
|
||||
$names = array();
|
||||
$names = [];
|
||||
foreach (array_keys($modules) as $name) {
|
||||
$names[$name] = $this->moduleHandler->getName($name);
|
||||
}
|
||||
|
||||
$form['data_module'] = array(
|
||||
$form['data_module'] = [
|
||||
'#title' => $this->t('Module name'),
|
||||
'#type' => 'select',
|
||||
'#description' => $this->t('The module which sets this user data.'),
|
||||
'#default_value' => $this->options['data_module'],
|
||||
'#options' => $names,
|
||||
);
|
||||
];
|
||||
|
||||
$form['data_name'] = array(
|
||||
$form['data_name'] = [
|
||||
'#title' => $this->t('Name'),
|
||||
'#type' => 'textfield',
|
||||
'#description' => $this->t('The name of the data key.'),
|
||||
'#default_value' => $this->options['data_name'],
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,9 +19,9 @@ class Name extends InOperator {
|
|||
protected $alwaysMultiple = TRUE;
|
||||
|
||||
protected function valueForm(&$form, FormStateInterface $form_state) {
|
||||
$users = $this->value ? User::loadMultiple($this->value) : array();
|
||||
$users = $this->value ? User::loadMultiple($this->value) : [];
|
||||
$default_value = EntityAutocomplete::getEntityLabels($users);
|
||||
$form['value'] = array(
|
||||
$form['value'] = [
|
||||
'#type' => 'entity_autocomplete',
|
||||
'#title' => $this->t('Usernames'),
|
||||
'#description' => $this->t('Enter a comma separated list of user names.'),
|
||||
|
@ -29,7 +29,7 @@ class Name extends InOperator {
|
|||
'#tags' => TRUE,
|
||||
'#default_value' => $default_value,
|
||||
'#process_default_value' => $this->isExposed(),
|
||||
);
|
||||
];
|
||||
|
||||
$user_input = $form_state->getUserInput();
|
||||
if ($form_state->get('exposed') && !isset($user_input[$this->options['expose']['identifier']])) {
|
||||
|
@ -40,13 +40,13 @@ class Name extends InOperator {
|
|||
|
||||
protected function valueValidate($form, FormStateInterface $form_state) {
|
||||
$uids = [];
|
||||
if ($values = $form_state->getValue(array('options', 'value'))) {
|
||||
if ($values = $form_state->getValue(['options', 'value'])) {
|
||||
foreach ($values as $value) {
|
||||
$uids[] = $value['target_id'];
|
||||
}
|
||||
sort($uids);
|
||||
}
|
||||
$form_state->setValue(array('options', 'value'), $uids);
|
||||
$form_state->setValue(['options', 'value'], $uids);
|
||||
}
|
||||
|
||||
public function acceptExposedInput($input) {
|
||||
|
@ -105,7 +105,7 @@ class Name extends InOperator {
|
|||
|
||||
public function adminSummary() {
|
||||
// set up $this->valueOptions for the parent summary
|
||||
$this->valueOptions = array();
|
||||
$this->valueOptions = [];
|
||||
|
||||
if ($this->value) {
|
||||
$result = \Drupal::entityTypeManager()->getStorage('user')
|
||||
|
|
|
@ -88,7 +88,7 @@ class Permissions extends ManyToOne {
|
|||
*/
|
||||
public function query() {
|
||||
// @todo user_role_names() should maybe support multiple permissions.
|
||||
$rids = array();
|
||||
$rids = [];
|
||||
// Get all role IDs that have the configured permissions.
|
||||
foreach ($this->value as $permission) {
|
||||
$roles = user_role_names(FALSE, $permission);
|
||||
|
|
|
@ -62,7 +62,7 @@ class Roles extends ManyToOne {
|
|||
/**
|
||||
* Override empty and not empty operator labels to be clearer for user roles.
|
||||
*/
|
||||
function operators() {
|
||||
public function operators() {
|
||||
$operators = parent::operators();
|
||||
$operators['empty']['title'] = $this->t("Only has the 'authenticated user' role");
|
||||
$operators['not empty']['title'] = $this->t("Has roles in addition to 'authenticated user'");
|
||||
|
@ -73,7 +73,7 @@ class Roles extends ManyToOne {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function calculateDependencies() {
|
||||
$dependencies = array();
|
||||
$dependencies = [];
|
||||
foreach ($this->value as $role_id) {
|
||||
$role = $this->roleStorage->load($role_id);
|
||||
$dependencies[$role->getConfigDependencyKey()][] = $role->getConfigDependencyName();
|
||||
|
|
|
@ -27,16 +27,16 @@ class Users extends WizardPluginBase {
|
|||
/**
|
||||
* Set default values for the filters.
|
||||
*/
|
||||
protected $filters = array(
|
||||
'status' => array(
|
||||
protected $filters = [
|
||||
'status' => [
|
||||
'value' => TRUE,
|
||||
'table' => 'users_field_data',
|
||||
'field' => 'status',
|
||||
'plugin_id' => 'boolean',
|
||||
'entity_type' => 'user',
|
||||
'entity_field' => 'status',
|
||||
)
|
||||
);
|
||||
]
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -112,6 +112,9 @@ class PrivateTempStore {
|
|||
* The key of the data to store.
|
||||
* @param mixed $value
|
||||
* The data to store.
|
||||
*
|
||||
* @throws \Drupal\user\TempStoreException
|
||||
* Thrown when a lock for the backend storage could not be acquired.
|
||||
*/
|
||||
public function set($key, $value) {
|
||||
$key = $this->createkey($key);
|
||||
|
@ -122,11 +125,11 @@ class PrivateTempStore {
|
|||
}
|
||||
}
|
||||
|
||||
$value = (object) array(
|
||||
$value = (object) [
|
||||
'owner' => $this->getOwner(),
|
||||
'data' => $value,
|
||||
'updated' => (int) $this->requestStack->getMasterRequest()->server->get('REQUEST_TIME'),
|
||||
);
|
||||
];
|
||||
$this->storage->setWithExpire($key, $value, $this->expire);
|
||||
$this->lockBackend->release($key);
|
||||
}
|
||||
|
@ -161,6 +164,9 @@ class PrivateTempStore {
|
|||
* @return bool
|
||||
* TRUE if the object was deleted or does not exist, FALSE if it exists but
|
||||
* is not owned by $this->owner.
|
||||
*
|
||||
* @throws \Drupal\user\TempStoreException
|
||||
* Thrown when a lock for the backend storage could not be acquired.
|
||||
*/
|
||||
public function delete($key) {
|
||||
$key = $this->createkey($key);
|
||||
|
|
|
@ -61,7 +61,7 @@ class PrivateTempStoreFactory {
|
|||
* @param int $expire
|
||||
* The time to live for items, in seconds.
|
||||
*/
|
||||
function __construct(KeyValueExpirableFactoryInterface $storage_factory, LockBackendInterface $lock_backend, AccountProxyInterface $current_user, RequestStack $request_stack, $expire = 604800) {
|
||||
public function __construct(KeyValueExpirableFactoryInterface $storage_factory, LockBackendInterface $lock_backend, AccountProxyInterface $current_user, RequestStack $request_stack, $expire = 604800) {
|
||||
$this->storageFactory = $storage_factory;
|
||||
$this->lockBackend = $lock_backend;
|
||||
$this->currentUser = $current_user;
|
||||
|
@ -79,7 +79,7 @@ class PrivateTempStoreFactory {
|
|||
* @return \Drupal\user\PrivateTempStore
|
||||
* An instance of the key/value store.
|
||||
*/
|
||||
function get($collection) {
|
||||
public function get($collection) {
|
||||
// Store the data for this collection in the database.
|
||||
$storage = $this->storageFactory->get("user.private_tempstore.$collection");
|
||||
return new PrivateTempStore($storage, $this->lockBackend, $this->currentUser, $this->requestStack, $this->expire);
|
||||
|
|
|
@ -2,23 +2,13 @@
|
|||
|
||||
namespace Drupal\user;
|
||||
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Entity\Query\QueryFactory;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Language\LanguageManagerInterface;
|
||||
|
||||
/**
|
||||
* Form handler for the profile forms.
|
||||
*/
|
||||
class ProfileForm extends AccountForm {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(EntityManagerInterface $entity_manager, LanguageManagerInterface $language_manager, QueryFactory $entity_query) {
|
||||
parent::__construct($entity_manager, $language_manager, $entity_query);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -32,7 +22,7 @@ class ProfileForm extends AccountForm {
|
|||
$user = $this->currentUser();
|
||||
$element['delete']['#type'] = 'submit';
|
||||
$element['delete']['#value'] = $this->t('Cancel account');
|
||||
$element['delete']['#submit'] = array('::editCancelSubmit');
|
||||
$element['delete']['#submit'] = ['::editCancelSubmit'];
|
||||
$element['delete']['#access'] = $account->id() > 1 && (($account->id() == $user->id() && $user->hasPermission('cancel account')) || $user->hasPermission('administer users'));
|
||||
|
||||
return $element;
|
||||
|
@ -53,17 +43,17 @@ class ProfileForm extends AccountForm {
|
|||
* Provides a submit handler for the 'Cancel account' button.
|
||||
*/
|
||||
public function editCancelSubmit($form, FormStateInterface $form_state) {
|
||||
$destination = array();
|
||||
$destination = [];
|
||||
$query = $this->getRequest()->query;
|
||||
if ($query->has('destination')) {
|
||||
$destination = array('destination' => $query->get('destination'));
|
||||
$destination = ['destination' => $query->get('destination')];
|
||||
$query->remove('destination');
|
||||
}
|
||||
// We redirect from user/%/edit to user/%/cancel to make the tabs disappear.
|
||||
$form_state->setRedirect(
|
||||
'entity.user.cancel_form',
|
||||
array('user' => $this->entity->id()),
|
||||
array('query' => $destination)
|
||||
['user' => $this->entity->id()],
|
||||
['query' => $destination]
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ class ProfileTranslationHandler extends ContentTranslationHandler {
|
|||
*/
|
||||
public function entityFormAlter(array &$form, FormStateInterface $form_state, EntityInterface $entity) {
|
||||
parent::entityFormAlter($form, $form_state, $entity);
|
||||
$form['actions']['submit']['#submit'][] = array($this, 'entityFormSave');
|
||||
$form['actions']['submit']['#submit'][] = [$this, 'entityFormSave'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,10 +20,10 @@ class RegisterForm extends AccountForm {
|
|||
// Pass access information to the submit handler. Running an access check
|
||||
// inside the submit function interferes with form processing and breaks
|
||||
// hook_form_alter().
|
||||
$form['administer_users'] = array(
|
||||
$form['administer_users'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => $admin,
|
||||
);
|
||||
];
|
||||
|
||||
$form['#attached']['library'][] = 'core/drupal.form';
|
||||
|
||||
|
@ -94,14 +94,14 @@ class RegisterForm extends AccountForm {
|
|||
$form_state->set('user', $account);
|
||||
$form_state->setValue('uid', $account->id());
|
||||
|
||||
$this->logger('user')->notice('New user: %name %email.', array('%name' => $form_state->getValue('name'), '%email' => '<' . $form_state->getValue('mail') . '>', 'type' => $account->link($this->t('Edit'), 'edit-form')));
|
||||
$this->logger('user')->notice('New user: %name %email.', ['%name' => $form_state->getValue('name'), '%email' => '<' . $form_state->getValue('mail') . '>', 'type' => $account->link($this->t('Edit'), 'edit-form')]);
|
||||
|
||||
// Add plain text password into user account to generate mail tokens.
|
||||
$account->password = $pass;
|
||||
|
||||
// New administrative account without notification.
|
||||
if ($admin && !$notify) {
|
||||
drupal_set_message($this->t('Created a new user account for <a href=":url">%name</a>. No email has been sent.', array(':url' => $account->url(), '%name' => $account->getUsername())));
|
||||
drupal_set_message($this->t('Created a new user account for <a href=":url">%name</a>. No email has been sent.', [':url' => $account->url(), '%name' => $account->getUsername()]));
|
||||
}
|
||||
// No email verification required; log in user immediately.
|
||||
elseif (!$admin && !\Drupal::config('user.settings')->get('verify_mail') && $account->isActive()) {
|
||||
|
@ -113,13 +113,13 @@ class RegisterForm extends AccountForm {
|
|||
// No administrator approval required.
|
||||
elseif ($account->isActive() || $notify) {
|
||||
if (!$account->getEmail() && $notify) {
|
||||
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' => $account->url(), '%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.', [':url' => $account->url(), '%name' => $account->getUsername()]));
|
||||
}
|
||||
else {
|
||||
$op = $notify ? 'register_admin_created' : 'register_no_approval_required';
|
||||
if (_user_mail_notify($op, $account)) {
|
||||
if ($notify) {
|
||||
drupal_set_message($this->t('A welcome message with further instructions has been emailed to the new user <a href=":url">%name</a>.', array(':url' => $account->url(), '%name' => $account->getUsername())));
|
||||
drupal_set_message($this->t('A welcome message with further instructions has been emailed to the new user <a href=":url">%name</a>.', [':url' => $account->url(), '%name' => $account->getUsername()]));
|
||||
}
|
||||
else {
|
||||
drupal_set_message($this->t('A welcome message with further instructions has been sent to your email address.'));
|
||||
|
|
|
@ -15,7 +15,7 @@ class RoleForm extends EntityForm {
|
|||
*/
|
||||
public function form(array $form, FormStateInterface $form_state) {
|
||||
$entity = $this->entity;
|
||||
$form['label'] = array(
|
||||
$form['label'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Role name'),
|
||||
'#default_value' => $entity->label(),
|
||||
|
@ -23,22 +23,22 @@ class RoleForm extends EntityForm {
|
|||
'#required' => TRUE,
|
||||
'#maxlength' => 64,
|
||||
'#description' => $this->t('The name for this role. Example: "Moderator", "Editorial board", "Site architect".'),
|
||||
);
|
||||
$form['id'] = array(
|
||||
];
|
||||
$form['id'] = [
|
||||
'#type' => 'machine_name',
|
||||
'#default_value' => $entity->id(),
|
||||
'#required' => TRUE,
|
||||
'#disabled' => !$entity->isNew(),
|
||||
'#size' => 30,
|
||||
'#maxlength' => 64,
|
||||
'#machine_name' => array(
|
||||
'#machine_name' => [
|
||||
'exists' => ['\Drupal\user\Entity\Role', 'load'],
|
||||
),
|
||||
);
|
||||
$form['weight'] = array(
|
||||
],
|
||||
];
|
||||
$form['weight'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => $entity->getWeight(),
|
||||
);
|
||||
];
|
||||
|
||||
return parent::form($form, $form_state, $entity);
|
||||
}
|
||||
|
@ -55,12 +55,12 @@ class RoleForm extends EntityForm {
|
|||
|
||||
$edit_link = $this->entity->link($this->t('Edit'));
|
||||
if ($status == SAVED_UPDATED) {
|
||||
drupal_set_message($this->t('Role %label has been updated.', array('%label' => $entity->label())));
|
||||
$this->logger('user')->notice('Role %label has been updated.', array('%label' => $entity->label(), 'link' => $edit_link));
|
||||
drupal_set_message($this->t('Role %label has been updated.', ['%label' => $entity->label()]));
|
||||
$this->logger('user')->notice('Role %label has been updated.', ['%label' => $entity->label(), 'link' => $edit_link]);
|
||||
}
|
||||
else {
|
||||
drupal_set_message($this->t('Role %label has been added.', array('%label' => $entity->label())));
|
||||
$this->logger('user')->notice('Role %label has been added.', array('%label' => $entity->label(), 'link' => $edit_link));
|
||||
drupal_set_message($this->t('Role %label has been added.', ['%label' => $entity->label()]));
|
||||
$this->logger('user')->notice('Role %label has been added.', ['%label' => $entity->label(), 'link' => $edit_link]);
|
||||
}
|
||||
$form_state->setRedirect('entity.user_role.collection');
|
||||
}
|
||||
|
|
|
@ -43,11 +43,11 @@ class RoleListBuilder extends DraggableListBuilder {
|
|||
$operations = parent::getDefaultOperations($entity);
|
||||
|
||||
if ($entity->hasLinkTemplate('edit-permissions-form')) {
|
||||
$operations['permissions'] = array(
|
||||
$operations['permissions'] = [
|
||||
'title' => t('Edit permissions'),
|
||||
'weight' => 20,
|
||||
'url' => $entity->urlInfo('edit-permissions-form'),
|
||||
);
|
||||
];
|
||||
}
|
||||
return $operations;
|
||||
}
|
||||
|
|
|
@ -142,11 +142,11 @@ class SharedTempStore {
|
|||
* TRUE if the data was set, or FALSE if it already existed.
|
||||
*/
|
||||
public function setIfNotExists($key, $value) {
|
||||
$value = (object) array(
|
||||
$value = (object) [
|
||||
'owner' => $this->owner,
|
||||
'data' => $value,
|
||||
'updated' => (int) $this->requestStack->getMasterRequest()->server->get('REQUEST_TIME'),
|
||||
);
|
||||
];
|
||||
return $this->storage->setWithExpireIfNotExists($key, $value, $this->expire);
|
||||
}
|
||||
|
||||
|
@ -164,6 +164,9 @@ class SharedTempStore {
|
|||
* @return bool
|
||||
* TRUE if the data was set, or FALSE if it already exists and is not owned
|
||||
* by $this->user.
|
||||
*
|
||||
* @throws \Drupal\user\TempStoreException
|
||||
* Thrown when a lock for the backend storage could not be acquired.
|
||||
*/
|
||||
public function setIfOwner($key, $value) {
|
||||
if ($this->setIfNotExists($key, $value)) {
|
||||
|
@ -185,6 +188,9 @@ class SharedTempStore {
|
|||
* The key of the data to store.
|
||||
* @param mixed $value
|
||||
* The data to store.
|
||||
*
|
||||
* @throws \Drupal\user\TempStoreException
|
||||
* Thrown when a lock for the backend storage could not be acquired.
|
||||
*/
|
||||
public function set($key, $value) {
|
||||
if (!$this->lockBackend->acquire($key)) {
|
||||
|
@ -194,11 +200,11 @@ class SharedTempStore {
|
|||
}
|
||||
}
|
||||
|
||||
$value = (object) array(
|
||||
$value = (object) [
|
||||
'owner' => $this->owner,
|
||||
'data' => $value,
|
||||
'updated' => (int) $this->requestStack->getMasterRequest()->server->get('REQUEST_TIME'),
|
||||
);
|
||||
];
|
||||
$this->storage->setWithExpire($key, $value, $this->expire);
|
||||
$this->lockBackend->release($key);
|
||||
}
|
||||
|
@ -228,6 +234,9 @@ class SharedTempStore {
|
|||
*
|
||||
* @param string $key
|
||||
* The key of the data to delete.
|
||||
*
|
||||
* @throws \Drupal\user\TempStoreException
|
||||
* Thrown when a lock for the backend storage could not be acquired.
|
||||
*/
|
||||
public function delete($key) {
|
||||
if (!$this->lockBackend->acquire($key)) {
|
||||
|
@ -251,6 +260,9 @@ class SharedTempStore {
|
|||
* @return bool
|
||||
* TRUE if the object was deleted or does not exist, FALSE if it exists but
|
||||
* is not owned by $this->owner.
|
||||
*
|
||||
* @throws \Drupal\user\TempStoreException
|
||||
* Thrown when a lock for the backend storage could not be acquired.
|
||||
*/
|
||||
public function deleteIfOwner($key) {
|
||||
if (!$object = $this->storage->get($key)) {
|
||||
|
|
|
@ -51,7 +51,7 @@ class SharedTempStoreFactory {
|
|||
* @param int $expire
|
||||
* The time to live for items, in seconds.
|
||||
*/
|
||||
function __construct(KeyValueExpirableFactoryInterface $storage_factory, LockBackendInterface $lock_backend, RequestStack $request_stack, $expire = 604800) {
|
||||
public function __construct(KeyValueExpirableFactoryInterface $storage_factory, LockBackendInterface $lock_backend, RequestStack $request_stack, $expire = 604800) {
|
||||
$this->storageFactory = $storage_factory;
|
||||
$this->lockBackend = $lock_backend;
|
||||
$this->requestStack = $request_stack;
|
||||
|
@ -72,7 +72,7 @@ class SharedTempStoreFactory {
|
|||
* @return \Drupal\user\SharedTempStore
|
||||
* An instance of the key/value store.
|
||||
*/
|
||||
function get($collection, $owner = NULL) {
|
||||
public function get($collection, $owner = NULL) {
|
||||
// Use the currently authenticated user ID or the active user ID unless
|
||||
// the owner is overridden.
|
||||
if (!isset($owner)) {
|
||||
|
|
172
web/core/modules/user/src/Tests/RestRegisterUserTest.php
Normal file
172
web/core/modules/user/src/Tests/RestRegisterUserTest.php
Normal file
|
@ -0,0 +1,172 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\user\Tests;
|
||||
|
||||
use Drupal\rest\Tests\RESTTestBase;
|
||||
use Drupal\user\Entity\Role;
|
||||
use Drupal\user\RoleInterface;
|
||||
|
||||
/**
|
||||
* Tests user registration via REST resource.
|
||||
*
|
||||
* @group user
|
||||
*/
|
||||
class RestRegisterUserTest extends RESTTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->enableService('user_registration', 'POST', 'hal_json');
|
||||
|
||||
Role::load(RoleInterface::ANONYMOUS_ID)
|
||||
->grantPermission('restful post user_registration')
|
||||
->save();
|
||||
|
||||
Role::load(RoleInterface::AUTHENTICATED_ID)
|
||||
->grantPermission('restful post user_registration')
|
||||
->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that only anonymous users can register users.
|
||||
*/
|
||||
public function testRegisterUser() {
|
||||
// Verify that an authenticated user cannot register a new user, despite
|
||||
// being granted permission to do so because only anonymous users can
|
||||
// register themselves, authenticated users with the necessary permissions
|
||||
// can POST a new user to the "user" REST resource.
|
||||
$user = $this->createUser();
|
||||
$this->drupalLogin($user);
|
||||
$this->registerRequest('palmer.eldritch');
|
||||
$this->assertResponse('403', 'Only anonymous users can register users.');
|
||||
$this->drupalLogout();
|
||||
|
||||
$user_settings = $this->config('user.settings');
|
||||
|
||||
// Test out different setting User Registration and Email Verification.
|
||||
// Allow visitors to register with no email verification.
|
||||
$user_settings->set('register', USER_REGISTER_VISITORS);
|
||||
$user_settings->set('verify_mail', 0);
|
||||
$user_settings->save();
|
||||
$user = $this->registerUser('Palmer.Eldritch');
|
||||
$this->assertFalse($user->isBlocked());
|
||||
$this->assertFalse(empty($user->getPassword()));
|
||||
$email_count = count($this->drupalGetMails());
|
||||
$this->assertEqual(0, $email_count);
|
||||
|
||||
// Attempt to register without sending a password.
|
||||
$this->registerRequest('Rick.Deckard', FALSE);
|
||||
$this->assertResponse('422', 'No password provided');
|
||||
|
||||
// Allow visitors to register with email verification.
|
||||
$user_settings->set('register', USER_REGISTER_VISITORS);
|
||||
$user_settings->set('verify_mail', 1);
|
||||
$user_settings->save();
|
||||
$user = $this->registerUser('Jason.Taverner', FALSE);
|
||||
$this->assertTrue(empty($user->getPassword()));
|
||||
$this->assertTrue($user->isBlocked());
|
||||
$this->assertMailString('body', 'You may now log in by clicking this link', 1);
|
||||
|
||||
// Attempt to register with a password when e-mail verification is on.
|
||||
$this->registerRequest('Estraven', TRUE);
|
||||
$this->assertResponse('422', 'A Password cannot be specified. It will be generated on login.');
|
||||
|
||||
// Allow visitors to register with Admin approval and e-mail verification.
|
||||
$user_settings->set('register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL);
|
||||
$user_settings->set('verify_mail', 1);
|
||||
$user_settings->save();
|
||||
$user = $this->registerUser('Bob.Arctor', FALSE);
|
||||
$this->assertTrue(empty($user->getPassword()));
|
||||
$this->assertTrue($user->isBlocked());
|
||||
$this->assertMailString('body', 'Your application for an account is', 2);
|
||||
$this->assertMailString('body', 'Bob.Arctor has applied for an account', 2);
|
||||
|
||||
// Attempt to register with a password when e-mail verification is on.
|
||||
$this->registerRequest('Ursula', TRUE);
|
||||
$this->assertResponse('422', 'A Password cannot be specified. It will be generated on login.');
|
||||
|
||||
// Allow visitors to register with Admin approval and no email verification.
|
||||
$user_settings->set('register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL);
|
||||
$user_settings->set('verify_mail', 0);
|
||||
$user_settings->save();
|
||||
$user = $this->registerUser('Argaven');
|
||||
$this->assertFalse(empty($user->getPassword()));
|
||||
$this->assertTrue($user->isBlocked());
|
||||
$this->assertMailString('body', 'Your application for an account is', 2);
|
||||
$this->assertMailString('body', 'Argaven has applied for an account', 2);
|
||||
|
||||
// Attempt to register without sending a password.
|
||||
$this->registerRequest('Tibe', FALSE);
|
||||
$this->assertResponse('422', 'No password provided');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates serialize user values.
|
||||
*
|
||||
* @param string $name
|
||||
* The name of the user. Use only valid values for emails.
|
||||
*
|
||||
* @param bool $include_password
|
||||
* Whether to include a password in the user values.
|
||||
*
|
||||
* @return string Serialized user values.
|
||||
* Serialized user values.
|
||||
*/
|
||||
protected function createSerializedUser($name, $include_password = TRUE) {
|
||||
global $base_url;
|
||||
// New user info to be serialized.
|
||||
$data = [
|
||||
"_links" => ["type" => ["href" => $base_url . "/rest/type/user/user"]],
|
||||
"langcode" => [["value" => "en"]],
|
||||
"name" => [["value" => $name]],
|
||||
"mail" => [["value" => "$name@example.com"]],
|
||||
];
|
||||
if ($include_password) {
|
||||
$data['pass']['value'] = 'SuperSecretPassword';
|
||||
}
|
||||
|
||||
// Create a HAL+JSON version for the user entity we want to create.
|
||||
$serialized = $this->container->get('serializer')
|
||||
->serialize($data, 'hal_json');
|
||||
return $serialized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a user via REST resource.
|
||||
*
|
||||
* @param $name
|
||||
* User name.
|
||||
*
|
||||
* @param bool $include_password
|
||||
*
|
||||
* @return bool|\Drupal\user\Entity\User
|
||||
*/
|
||||
protected function registerUser($name, $include_password = TRUE) {
|
||||
// Verify that an anonymous user can register.
|
||||
$this->registerRequest($name, $include_password);
|
||||
$this->assertResponse('200', 'HTTP response code is correct.');
|
||||
$user = user_load_by_name($name);
|
||||
$this->assertFalse(empty($user), 'User was create as expected');
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a REST user registration request.
|
||||
*
|
||||
* @param $name
|
||||
* @param $include_password
|
||||
*/
|
||||
protected function registerRequest($name, $include_password = TRUE) {
|
||||
$serialized = $this->createSerializedUser($name, $include_password);
|
||||
$this->httpRequest('/user/register', 'POST', $serialized, 'application/hal+json');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\user\Tests\Update;
|
||||
|
||||
use Drupal\system\Tests\Update\UpdatePathTestBase;
|
||||
use Drupal\user\Entity\Role;
|
||||
|
||||
/**
|
||||
* Tests user permissions sort upgrade path.
|
||||
*
|
||||
* @group Update
|
||||
*/
|
||||
class UserUpdateOrderPermissionsTest extends UpdatePathTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setDatabaseDumpFiles() {
|
||||
$this->databaseDumpFiles = [
|
||||
__DIR__ . '/../../../../system/tests/fixtures/update/drupal-8-rc1.bare.standard.php.gz',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that permissions are ordered by machine name.
|
||||
*/
|
||||
public function testPermissionsOrder() {
|
||||
$authenticated = Role::load('authenticated');
|
||||
$permissions = $authenticated->getPermissions();
|
||||
sort($permissions);
|
||||
$this->assertNotIdentical($permissions, $authenticated->getPermissions());
|
||||
|
||||
$this->runUpdates();
|
||||
$authenticated = Role::load('authenticated');
|
||||
$this->assertIdentical($permissions, $authenticated->getPermissions());
|
||||
}
|
||||
|
||||
}
|
|
@ -16,7 +16,7 @@ class UserAccountLinksTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('menu_ui', 'block', 'test_page_test');
|
||||
public static $modules = ['menu_ui', 'block', 'test_page_test'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -31,9 +31,9 @@ class UserAccountLinksTest extends WebTestBase {
|
|||
/**
|
||||
* Tests the secondary menu.
|
||||
*/
|
||||
function testSecondaryMenu() {
|
||||
public function testSecondaryMenu() {
|
||||
// Create a regular user.
|
||||
$user = $this->drupalCreateUser(array());
|
||||
$user = $this->drupalCreateUser([]);
|
||||
|
||||
// Log in and get the homepage.
|
||||
$this->drupalLogin($user);
|
||||
|
@ -41,18 +41,18 @@ class UserAccountLinksTest extends WebTestBase {
|
|||
|
||||
// For a logged-in user, expect the secondary menu to have links for "My
|
||||
// account" and "Log out".
|
||||
$link = $this->xpath('//ul[@class=:menu_class]/li/a[contains(@href, :href) and text()=:text]', array(
|
||||
$link = $this->xpath('//ul[@class=:menu_class]/li/a[contains(@href, :href) and text()=:text]', [
|
||||
':menu_class' => 'menu',
|
||||
':href' => 'user',
|
||||
':text' => 'My account',
|
||||
));
|
||||
]);
|
||||
$this->assertEqual(count($link), 1, 'My account link is in secondary menu.');
|
||||
|
||||
$link = $this->xpath('//ul[@class=:menu_class]/li/a[contains(@href, :href) and text()=:text]', array(
|
||||
$link = $this->xpath('//ul[@class=:menu_class]/li/a[contains(@href, :href) and text()=:text]', [
|
||||
':menu_class' => 'menu',
|
||||
':href' => 'user/logout',
|
||||
':text' => 'Log out',
|
||||
));
|
||||
]);
|
||||
$this->assertEqual(count($link), 1, 'Log out link is in secondary menu.');
|
||||
|
||||
// Log out and get the homepage.
|
||||
|
@ -60,35 +60,35 @@ class UserAccountLinksTest extends WebTestBase {
|
|||
$this->drupalGet('<front>');
|
||||
|
||||
// For a logged-out user, expect the secondary menu to have a "Log in" link.
|
||||
$link = $this->xpath('//ul[@class=:menu_class]/li/a[contains(@href, :href) and text()=:text]', array(
|
||||
$link = $this->xpath('//ul[@class=:menu_class]/li/a[contains(@href, :href) and text()=:text]', [
|
||||
':menu_class' => 'menu',
|
||||
':href' => 'user/login',
|
||||
':text' => 'Log in',
|
||||
));
|
||||
]);
|
||||
$this->assertEqual(count($link), 1, 'Log in link is in secondary menu.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests disabling the 'My account' link.
|
||||
*/
|
||||
function testDisabledAccountLink() {
|
||||
public function testDisabledAccountLink() {
|
||||
// Create an admin user and log in.
|
||||
$this->drupalLogin($this->drupalCreateUser(array('access administration pages', 'administer menu')));
|
||||
$this->drupalLogin($this->drupalCreateUser(['access administration pages', 'administer menu']));
|
||||
|
||||
// Verify that the 'My account' link exists before we check for its
|
||||
// disappearance.
|
||||
$link = $this->xpath('//ul[@class=:menu_class]/li/a[contains(@href, :href) and text()=:text]', array(
|
||||
$link = $this->xpath('//ul[@class=:menu_class]/li/a[contains(@href, :href) and text()=:text]', [
|
||||
':menu_class' => 'menu',
|
||||
':href' => 'user',
|
||||
':text' => 'My account',
|
||||
));
|
||||
]);
|
||||
$this->assertEqual(count($link), 1, 'My account link is in the secondary menu.');
|
||||
|
||||
// Verify that the 'My account' link is enabled. Do not assume the value of
|
||||
// auto-increment is 1. Use XPath to obtain input element id and name using
|
||||
// the consistent label text.
|
||||
$this->drupalGet('admin/structure/menu/manage/account');
|
||||
$label = $this->xpath('//label[contains(.,:text)]/@for', array(':text' => 'Enable My account menu link'));
|
||||
$label = $this->xpath('//label[contains(.,:text)]/@for', [':text' => 'Enable My account menu link']);
|
||||
$this->assertFieldChecked((string) $label[0], "The 'My account' link is enabled by default.");
|
||||
|
||||
// Disable the 'My account' link.
|
||||
|
@ -99,18 +99,18 @@ class UserAccountLinksTest extends WebTestBase {
|
|||
$this->drupalGet('<front>');
|
||||
|
||||
// Verify that the 'My account' link does not appear when disabled.
|
||||
$link = $this->xpath('//ul[@class=:menu_class]/li/a[contains(@href, :href) and text()=:text]', array(
|
||||
$link = $this->xpath('//ul[@class=:menu_class]/li/a[contains(@href, :href) and text()=:text]', [
|
||||
':menu_class' => 'menu',
|
||||
':href' => 'user',
|
||||
':text' => 'My account',
|
||||
));
|
||||
]);
|
||||
$this->assertEqual(count($link), 0, 'My account link is not in the secondary menu.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests page title is set correctly on user account tabs.
|
||||
*/
|
||||
function testAccountPageTitles() {
|
||||
public function testAccountPageTitles() {
|
||||
// Default page titles are suffixed with the site name - Drupal.
|
||||
$title_suffix = ' | Drupal';
|
||||
|
||||
|
|
|
@ -31,12 +31,12 @@ class UserAdminLanguageTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('user', 'language', 'language_test');
|
||||
public static $modules = ['user', 'language', 'language_test'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
// User to add and remove language.
|
||||
$this->adminUser = $this->drupalCreateUser(array('administer languages', 'access administration pages'));
|
||||
$this->adminUser = $this->drupalCreateUser(['administer languages', 'access administration pages']);
|
||||
// User to check non-admin access.
|
||||
$this->regularUser = $this->drupalCreateUser();
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ class UserAdminLanguageTest extends WebTestBase {
|
|||
/**
|
||||
* Tests that admin language is not configurable in single language sites.
|
||||
*/
|
||||
function testUserAdminLanguageConfigurationNotAvailableWithOnlyOneLanguage() {
|
||||
public function testUserAdminLanguageConfigurationNotAvailableWithOnlyOneLanguage() {
|
||||
$this->drupalLogin($this->adminUser);
|
||||
$this->setLanguageNegotiation();
|
||||
$path = 'user/' . $this->adminUser->id() . '/edit';
|
||||
|
@ -56,7 +56,7 @@ class UserAdminLanguageTest extends WebTestBase {
|
|||
/**
|
||||
* Tests that admin language negotiation is configurable only if enabled.
|
||||
*/
|
||||
function testUserAdminLanguageConfigurationAvailableWithAdminLanguageNegotiation() {
|
||||
public function testUserAdminLanguageConfigurationAvailableWithAdminLanguageNegotiation() {
|
||||
$this->drupalLogin($this->adminUser);
|
||||
$this->addCustomLanguage();
|
||||
$path = 'user/' . $this->adminUser->id() . '/edit';
|
||||
|
@ -83,7 +83,7 @@ class UserAdminLanguageTest extends WebTestBase {
|
|||
* have a setting for pages they cannot access, so they should not be able to
|
||||
* set a language for those pages.
|
||||
*/
|
||||
function testUserAdminLanguageConfigurationAvailableIfAdminLanguageNegotiationIsEnabled() {
|
||||
public function testUserAdminLanguageConfigurationAvailableIfAdminLanguageNegotiationIsEnabled() {
|
||||
$this->drupalLogin($this->adminUser);
|
||||
// Adds a new language, because with only one language, setting won't show.
|
||||
$this->addCustomLanguage();
|
||||
|
@ -103,7 +103,7 @@ class UserAdminLanguageTest extends WebTestBase {
|
|||
/**
|
||||
* Tests the actual language negotiation.
|
||||
*/
|
||||
function testActualNegotiation() {
|
||||
public function testActualNegotiation() {
|
||||
$this->drupalLogin($this->adminUser);
|
||||
$this->addCustomLanguage();
|
||||
$this->setLanguageNegotiation();
|
||||
|
@ -117,7 +117,7 @@ class UserAdminLanguageTest extends WebTestBase {
|
|||
$this->assertText('Language negotiation method: language-url');
|
||||
|
||||
// Set a preferred language code for the user.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['preferred_admin_langcode'] = 'xx';
|
||||
$this->drupalPostForm($path, $edit, t('Save'));
|
||||
|
||||
|
@ -137,7 +137,7 @@ class UserAdminLanguageTest extends WebTestBase {
|
|||
$this->assertText('Language negotiation method: language-user-admin');
|
||||
|
||||
// Unset the preferred language code for the user.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['preferred_admin_langcode'] = '';
|
||||
$this->drupalPostForm($path, $edit, t('Save'));
|
||||
$this->drupalGet($path);
|
||||
|
@ -155,29 +155,29 @@ class UserAdminLanguageTest extends WebTestBase {
|
|||
* @param bool $admin_first
|
||||
* Whether the admin negotiation should be first.
|
||||
*/
|
||||
function setLanguageNegotiation($admin_first = FALSE) {
|
||||
$edit = array(
|
||||
public function setLanguageNegotiation($admin_first = FALSE) {
|
||||
$edit = [
|
||||
'language_interface[enabled][language-user-admin]' => TRUE,
|
||||
'language_interface[enabled][language-url]' => TRUE,
|
||||
'language_interface[weight][language-user-admin]' => ($admin_first ? -12 : -8),
|
||||
'language_interface[weight][language-url]' => -10,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method for adding a custom language.
|
||||
*/
|
||||
function addCustomLanguage() {
|
||||
public function addCustomLanguage() {
|
||||
$langcode = 'xx';
|
||||
// The English name for the language.
|
||||
$name = $this->randomMachineName(16);
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'predefined_langcode' => 'custom',
|
||||
'langcode' => $langcode,
|
||||
'label' => $name,
|
||||
'direction' => LanguageInterface::DIRECTION_LTR,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ class UserAdminListingTest extends WebTestBase {
|
|||
$this->assertResponse(403, 'Anonymous user does not have access to the user admin listing.');
|
||||
|
||||
// Create a bunch of users.
|
||||
$accounts = array();
|
||||
$accounts = [];
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$account = $this->drupalCreateUser();
|
||||
$accounts[$account->label()] = $account;
|
||||
|
@ -39,8 +39,8 @@ class UserAdminListingTest extends WebTestBase {
|
|||
$accounts[$account->label()] = $account;
|
||||
$timestamp_user = $account->label();
|
||||
|
||||
$rid_1 = $this->drupalCreateRole(array(), 'custom_role_1', 'custom_role_1');
|
||||
$rid_2 = $this->drupalCreateRole(array(), 'custom_role_2', 'custom_role_2');
|
||||
$rid_1 = $this->drupalCreateRole([], 'custom_role_1', 'custom_role_1');
|
||||
$rid_2 = $this->drupalCreateRole([], 'custom_role_2', 'custom_role_2');
|
||||
|
||||
$account = $this->drupalCreateUser();
|
||||
$account->addRole($rid_1);
|
||||
|
@ -50,7 +50,7 @@ class UserAdminListingTest extends WebTestBase {
|
|||
$role_account_name = $account->label();
|
||||
|
||||
// Create an admin user and look at the listing.
|
||||
$admin_user = $this->drupalCreateUser(array('administer users'));
|
||||
$admin_user = $this->drupalCreateUser(['administer users']);
|
||||
$accounts[$admin_user->label()] = $admin_user;
|
||||
|
||||
$accounts['admin'] = User::load(1);
|
||||
|
@ -61,22 +61,22 @@ class UserAdminListingTest extends WebTestBase {
|
|||
$this->assertResponse(200, 'The admin user has access to the user admin listing.');
|
||||
|
||||
$result = $this->xpath('//table[contains(@class, "responsive-enabled")]/tbody/tr');
|
||||
$result_accounts = array();
|
||||
$result_accounts = [];
|
||||
foreach ($result as $account) {
|
||||
$name = (string) $account->td[0]->span;
|
||||
$roles = array();
|
||||
$roles = [];
|
||||
if (isset($account->td[2]->div->ul)) {
|
||||
foreach ($account->td[2]->div->ul->li as $element) {
|
||||
$roles[] = (string) $element;
|
||||
}
|
||||
}
|
||||
$result_accounts[$name] = array(
|
||||
$result_accounts[$name] = [
|
||||
'name' => $name,
|
||||
'status' => (string) $account->td[1],
|
||||
'roles' => $roles,
|
||||
'member_for' => (string) $account->td[3],
|
||||
'last_access' => (string) $account->td[4],
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
$this->assertFalse(array_keys(array_diff_key($result_accounts, $accounts)), 'Ensure all accounts are listed.');
|
||||
|
@ -84,7 +84,7 @@ class UserAdminListingTest extends WebTestBase {
|
|||
$this->assertEqual($values['status'] == t('active'), $accounts[$name]->status->value, 'Ensure the status is displayed properly.');
|
||||
}
|
||||
|
||||
$expected_roles = array('custom_role_1', 'custom_role_2');
|
||||
$expected_roles = ['custom_role_1', 'custom_role_2'];
|
||||
$this->assertEqual($result_accounts[$role_account_name]['roles'], $expected_roles, 'Ensure roles are listed properly.');
|
||||
|
||||
$this->assertEqual($result_accounts[$timestamp_user]['member_for'], \Drupal::service('date.formatter')->formatTimeDiffSince($accounts[$timestamp_user]->created->value), 'Ensure the right member time is displayed.');
|
||||
|
|
|
@ -16,33 +16,33 @@ class UserAdminSettingsFormTest extends SystemConfigFormTestBase {
|
|||
parent::setUp();
|
||||
|
||||
$this->form = AccountSettingsForm::create($this->container);
|
||||
$this->values = array(
|
||||
'anonymous' => array(
|
||||
$this->values = [
|
||||
'anonymous' => [
|
||||
'#value' => $this->randomString(10),
|
||||
'#config_name' => 'user.settings',
|
||||
'#config_key' => 'anonymous',
|
||||
),
|
||||
'user_mail_cancel_confirm_body' => array(
|
||||
],
|
||||
'user_mail_cancel_confirm_body' => [
|
||||
'#value' => $this->randomString(),
|
||||
'#config_name' => 'user.mail',
|
||||
'#config_key' => 'cancel_confirm.body',
|
||||
),
|
||||
'user_mail_cancel_confirm_subject' => array(
|
||||
],
|
||||
'user_mail_cancel_confirm_subject' => [
|
||||
'#value' => $this->randomString(20),
|
||||
'#config_name' => 'user.mail',
|
||||
'#config_key' => 'cancel_confirm.subject',
|
||||
),
|
||||
'register_pending_approval_admin_body' => array(
|
||||
],
|
||||
'register_pending_approval_admin_body' => [
|
||||
'#value' => $this->randomString(),
|
||||
'#config_name' => 'user.mail',
|
||||
'#config_key' => 'register_pending_approval_admin.body',
|
||||
),
|
||||
'register_pending_approval_admin_subject' => array(
|
||||
],
|
||||
'register_pending_approval_admin_subject' => [
|
||||
'#value' => $this->randomString(20),
|
||||
'#config_name' => 'user.mail',
|
||||
'#config_key' => 'register_pending_approval_admin.subject',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,28 +17,28 @@ class UserAdminTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('taxonomy', 'views');
|
||||
public static $modules = ['taxonomy', 'views'];
|
||||
|
||||
/**
|
||||
* Registers a user and deletes it.
|
||||
*/
|
||||
function testUserAdmin() {
|
||||
public function testUserAdmin() {
|
||||
$config = $this->config('user.settings');
|
||||
$user_a = $this->drupalCreateUser();
|
||||
$user_a->name = 'User A';
|
||||
$user_a->mail = $this->randomMachineName() . '@example.com';
|
||||
$user_a->save();
|
||||
$user_b = $this->drupalCreateUser(array('administer taxonomy'));
|
||||
$user_b = $this->drupalCreateUser(['administer taxonomy']);
|
||||
$user_b->name = 'User B';
|
||||
$user_b->save();
|
||||
$user_c = $this->drupalCreateUser(array('administer taxonomy'));
|
||||
$user_c = $this->drupalCreateUser(['administer taxonomy']);
|
||||
$user_c->name = 'User C';
|
||||
$user_c->save();
|
||||
|
||||
$user_storage = $this->container->get('entity.manager')->getStorage('user');
|
||||
|
||||
// Create admin user to delete registered user.
|
||||
$admin_user = $this->drupalCreateUser(array('administer users'));
|
||||
$admin_user = $this->drupalCreateUser(['administer users']);
|
||||
// Use a predictable name so that we can reliably order the user admin page
|
||||
// by name.
|
||||
$admin_user->name = 'Admin user';
|
||||
|
@ -51,11 +51,11 @@ class UserAdminTest extends WebTestBase {
|
|||
$this->assertText($admin_user->getUsername(), 'Found Admin user on admin users page');
|
||||
|
||||
// Test for existence of edit link in table.
|
||||
$link = $user_a->link(t('Edit'), 'edit-form', array('query' => array('destination' => $user_a->url('collection'))));
|
||||
$link = $user_a->link(t('Edit'), 'edit-form', ['query' => ['destination' => $user_a->url('collection')]]);
|
||||
$this->assertRaw($link, 'Found user A edit link on admin users page');
|
||||
|
||||
// Test exposed filter elements.
|
||||
foreach (array('user', 'role', 'permission', 'status') as $field) {
|
||||
foreach (['user', 'role', 'permission', 'status'] as $field) {
|
||||
$this->assertField("edit-$field", "$field exposed filter found.");
|
||||
}
|
||||
// Make sure the reduce duplicates element from the ManyToOneHelper is not
|
||||
|
@ -63,18 +63,18 @@ class UserAdminTest extends WebTestBase {
|
|||
$this->assertNoField('edit-reduce-duplicates', 'Reduce duplicates form element not found in exposed filters.');
|
||||
|
||||
// Filter the users by name/email.
|
||||
$this->drupalGet('admin/people', array('query' => array('user' => $user_a->getUsername())));
|
||||
$this->drupalGet('admin/people', ['query' => ['user' => $user_a->getUsername()]]);
|
||||
$result = $this->xpath('//table/tbody/tr');
|
||||
$this->assertEqual(1, count($result), 'Filter by username returned the right amount.');
|
||||
$this->assertEqual($user_a->getUsername(), (string) $result[0]->td[1]->span, 'Filter by username returned the right user.');
|
||||
|
||||
$this->drupalGet('admin/people', array('query' => array('user' => $user_a->getEmail())));
|
||||
$this->drupalGet('admin/people', ['query' => ['user' => $user_a->getEmail()]]);
|
||||
$result = $this->xpath('//table/tbody/tr');
|
||||
$this->assertEqual(1, count($result), 'Filter by username returned the right amount.');
|
||||
$this->assertEqual($user_a->getUsername(), (string) $result[0]->td[1]->span, 'Filter by username returned the right user.');
|
||||
|
||||
// Filter the users by permission 'administer taxonomy'.
|
||||
$this->drupalGet('admin/people', array('query' => array('permission' => 'administer taxonomy')));
|
||||
$this->drupalGet('admin/people', ['query' => ['permission' => 'administer taxonomy']]);
|
||||
|
||||
// Check if the correct users show up.
|
||||
$this->assertNoText($user_a->getUsername(), 'User A not on filtered by perm admin users page');
|
||||
|
@ -84,7 +84,7 @@ class UserAdminTest extends WebTestBase {
|
|||
// Filter the users by role. Grab the system-generated role name for User C.
|
||||
$roles = $user_c->getRoles();
|
||||
unset($roles[array_search(RoleInterface::AUTHENTICATED_ID, $roles)]);
|
||||
$this->drupalGet('admin/people', array('query' => array('role' => reset($roles))));
|
||||
$this->drupalGet('admin/people', ['query' => ['role' => reset($roles)]]);
|
||||
|
||||
// Check if the correct users show up when filtered by role.
|
||||
$this->assertNoText($user_a->getUsername(), 'User A not on filtered by role on admin users page');
|
||||
|
@ -94,53 +94,53 @@ class UserAdminTest extends WebTestBase {
|
|||
// Test blocking of a user.
|
||||
$account = $user_storage->load($user_c->id());
|
||||
$this->assertTrue($account->isActive(), 'User C not blocked');
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['action'] = 'user_block_user_action';
|
||||
$edit['user_bulk_form[4]'] = TRUE;
|
||||
$config
|
||||
->set('notify.status_blocked', TRUE)
|
||||
->save();
|
||||
$this->drupalPostForm('admin/people', $edit, t('Apply to selected items'), array(
|
||||
$this->drupalPostForm('admin/people', $edit, t('Apply to selected items'), [
|
||||
// Sort the table by username so that we know reliably which user will be
|
||||
// targeted with the blocking action.
|
||||
'query' => array('order' => 'name', 'sort' => 'asc')
|
||||
));
|
||||
'query' => ['order' => 'name', 'sort' => 'asc']
|
||||
]);
|
||||
$site_name = $this->config('system.site')->get('name');
|
||||
$this->assertMailString('body', 'Your account on ' . $site_name . ' has been blocked.', 1, 'Blocked message found in the mail sent to user C.');
|
||||
$user_storage->resetCache(array($user_c->id()));
|
||||
$user_storage->resetCache([$user_c->id()]);
|
||||
$account = $user_storage->load($user_c->id());
|
||||
$this->assertTrue($account->isBlocked(), 'User C blocked');
|
||||
|
||||
// Test filtering on admin page for blocked users
|
||||
$this->drupalGet('admin/people', array('query' => array('status' => 2)));
|
||||
$this->drupalGet('admin/people', ['query' => ['status' => 2]]);
|
||||
$this->assertNoText($user_a->getUsername(), 'User A not on filtered by status on admin users page');
|
||||
$this->assertNoText($user_b->getUsername(), 'User B not on filtered by status on admin users page');
|
||||
$this->assertText($user_c->getUsername(), 'User C on filtered by status on admin users page');
|
||||
|
||||
// Test unblocking of a user from /admin/people page and sending of activation mail
|
||||
$editunblock = array();
|
||||
$editunblock = [];
|
||||
$editunblock['action'] = 'user_unblock_user_action';
|
||||
$editunblock['user_bulk_form[4]'] = TRUE;
|
||||
$this->drupalPostForm('admin/people', $editunblock, t('Apply to selected items'), array(
|
||||
$this->drupalPostForm('admin/people', $editunblock, t('Apply to selected items'), [
|
||||
// Sort the table by username so that we know reliably which user will be
|
||||
// targeted with the blocking action.
|
||||
'query' => array('order' => 'name', 'sort' => 'asc')
|
||||
));
|
||||
$user_storage->resetCache(array($user_c->id()));
|
||||
'query' => ['order' => 'name', 'sort' => 'asc']
|
||||
]);
|
||||
$user_storage->resetCache([$user_c->id()]);
|
||||
$account = $user_storage->load($user_c->id());
|
||||
$this->assertTrue($account->isActive(), 'User C unblocked');
|
||||
$this->assertMail("to", $account->getEmail(), "Activation mail sent to user C");
|
||||
|
||||
// Test blocking and unblocking another user from /user/[uid]/edit form and sending of activation mail
|
||||
$user_d = $this->drupalCreateUser(array());
|
||||
$user_storage->resetCache(array($user_d->id()));
|
||||
$user_d = $this->drupalCreateUser([]);
|
||||
$user_storage->resetCache([$user_d->id()]);
|
||||
$account1 = $user_storage->load($user_d->id());
|
||||
$this->drupalPostForm('user/' . $account1->id() . '/edit', array('status' => 0), t('Save'));
|
||||
$user_storage->resetCache(array($user_d->id()));
|
||||
$this->drupalPostForm('user/' . $account1->id() . '/edit', ['status' => 0], t('Save'));
|
||||
$user_storage->resetCache([$user_d->id()]);
|
||||
$account1 = $user_storage->load($user_d->id());
|
||||
$this->assertTrue($account1->isBlocked(), 'User D blocked');
|
||||
$this->drupalPostForm('user/' . $account1->id() . '/edit', array('status' => TRUE), t('Save'));
|
||||
$user_storage->resetCache(array($user_d->id()));
|
||||
$this->drupalPostForm('user/' . $account1->id() . '/edit', ['status' => TRUE], t('Save'));
|
||||
$user_storage->resetCache([$user_d->id()]);
|
||||
$account1 = $user_storage->load($user_d->id());
|
||||
$this->assertTrue($account1->isActive(), 'User D unblocked');
|
||||
$this->assertMail("to", $account1->getEmail(), "Activation mail sent to user D");
|
||||
|
@ -149,9 +149,9 @@ class UserAdminTest extends WebTestBase {
|
|||
/**
|
||||
* Tests the alternate notification email address for user mails.
|
||||
*/
|
||||
function testNotificationEmailAddress() {
|
||||
public function testNotificationEmailAddress() {
|
||||
// Test that the Notification Email address field is on the config page.
|
||||
$admin_user = $this->drupalCreateUser(array('administer users', 'administer account settings'));
|
||||
$admin_user = $this->drupalCreateUser(['administer users', 'administer account settings']);
|
||||
$this->drupalLogin($admin_user);
|
||||
$this->drupalGet('admin/config/people/accounts');
|
||||
$this->assertRaw('id="edit-mail-notification-address"', 'Notification Email address field exists');
|
||||
|
@ -173,27 +173,27 @@ class UserAdminTest extends WebTestBase {
|
|||
->set('mail_notification', $notify_address)
|
||||
->save();
|
||||
// Register a new user account.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['name'] = $this->randomMachineName();
|
||||
$edit['mail'] = $edit['name'] . '@example.com';
|
||||
$this->drupalPostForm('user/register', $edit, t('Create new account'));
|
||||
$subject = 'Account details for ' . $edit['name'] . ' at ' . $system->get('name') . ' (pending admin approval)';
|
||||
// Ensure that admin notification mail is sent to the configured
|
||||
// Notification Email address.
|
||||
$admin_mail = $this->drupalGetMails(array(
|
||||
$admin_mail = $this->drupalGetMails([
|
||||
'to' => $notify_address,
|
||||
'from' => $server_address,
|
||||
'subject' => $subject,
|
||||
));
|
||||
]);
|
||||
$this->assertTrue(count($admin_mail), 'New user mail to admin is sent to configured Notification Email address');
|
||||
// Ensure that user notification mail is sent from the configured
|
||||
// Notification Email address.
|
||||
$user_mail = $this->drupalGetMails(array(
|
||||
$user_mail = $this->drupalGetMails([
|
||||
'to' => $edit['mail'],
|
||||
'from' => $server_address,
|
||||
'reply-to' => $notify_address,
|
||||
'subject' => $subject,
|
||||
));
|
||||
]);
|
||||
$this->assertTrue(count($user_mail), 'New user mail to user is sent from configured Notification Email address');
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ class UserBlocksTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block', 'views');
|
||||
public static $modules = ['block', 'views'];
|
||||
|
||||
/**
|
||||
* A user with the 'administer blocks' permission.
|
||||
|
@ -28,7 +28,7 @@ class UserBlocksTest extends WebTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->adminUser = $this->drupalCreateUser(array('administer blocks'));
|
||||
$this->adminUser = $this->drupalCreateUser(['administer blocks']);
|
||||
$this->drupalLogin($this->adminUser);
|
||||
$this->drupalPlaceBlock('user_login_block');
|
||||
$this->drupalLogout($this->adminUser);
|
||||
|
@ -37,7 +37,7 @@ class UserBlocksTest extends WebTestBase {
|
|||
/**
|
||||
* Tests that user login block is hidden from user/login.
|
||||
*/
|
||||
function testUserLoginBlockVisibility() {
|
||||
public function testUserLoginBlockVisibility() {
|
||||
// Array keyed list where key being the URL address and value being expected
|
||||
// visibility as boolean type.
|
||||
$paths = [
|
||||
|
@ -61,12 +61,12 @@ class UserBlocksTest extends WebTestBase {
|
|||
/**
|
||||
* Test the user login block.
|
||||
*/
|
||||
function testUserLoginBlock() {
|
||||
public function testUserLoginBlock() {
|
||||
// Create a user with some permission that anonymous users lack.
|
||||
$user = $this->drupalCreateUser(array('administer permissions'));
|
||||
$user = $this->drupalCreateUser(['administer permissions']);
|
||||
|
||||
// Log in using the block.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['name'] = $user->getUsername();
|
||||
$edit['pass'] = $user->pass_raw;
|
||||
$this->drupalPostForm('admin/people/permissions', $edit, t('Log in'));
|
||||
|
@ -84,14 +84,14 @@ class UserBlocksTest extends WebTestBase {
|
|||
// Check that the user login block is not vulnerable to information
|
||||
// disclosure to third party sites.
|
||||
$this->drupalLogout();
|
||||
$this->drupalPostForm('http://example.com/', $edit, t('Log in'), array('external' => FALSE));
|
||||
$this->drupalPostForm('http://example.com/', $edit, t('Log in'), ['external' => FALSE]);
|
||||
// Check that we remain on the site after login.
|
||||
$this->assertUrl($user->url('canonical', ['absolute' => TRUE]), [], 'Redirected to user profile page after login from the frontpage');
|
||||
|
||||
// Verify that form validation errors are displayed immediately for forms
|
||||
// in blocks and not on subsequent page requests.
|
||||
$this->drupalLogout();
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['name'] = 'foo';
|
||||
$edit['pass'] = 'invalid password';
|
||||
$this->drupalPostForm('filter/tips', $edit, t('Log in'));
|
||||
|
@ -103,13 +103,13 @@ class UserBlocksTest extends WebTestBase {
|
|||
/**
|
||||
* Test the Who's Online block.
|
||||
*/
|
||||
function testWhosOnlineBlock() {
|
||||
public function testWhosOnlineBlock() {
|
||||
$block = $this->drupalPlaceBlock('views_block:who_s_online-who_s_online_block');
|
||||
|
||||
// Generate users.
|
||||
$user1 = $this->drupalCreateUser(array('access user profiles'));
|
||||
$user2 = $this->drupalCreateUser(array());
|
||||
$user3 = $this->drupalCreateUser(array());
|
||||
$user1 = $this->drupalCreateUser(['access user profiles']);
|
||||
$user2 = $this->drupalCreateUser([]);
|
||||
$user3 = $this->drupalCreateUser([]);
|
||||
|
||||
// Update access of two users to be within the active timespan.
|
||||
$this->updateAccess($user1->id());
|
||||
|
@ -138,7 +138,7 @@ class UserBlocksTest extends WebTestBase {
|
|||
private function updateAccess($uid, $access = REQUEST_TIME) {
|
||||
db_update('users_field_data')
|
||||
->condition('uid', $uid)
|
||||
->fields(array('access' => $access))
|
||||
->fields(['access' => $access])
|
||||
->execute();
|
||||
}
|
||||
|
||||
|
|
|
@ -22,31 +22,31 @@ class UserCancelTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'comment');
|
||||
public static $modules = ['node', 'comment'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to cancel account without permission.
|
||||
*/
|
||||
function testUserCancelWithoutPermission() {
|
||||
public function testUserCancelWithoutPermission() {
|
||||
$node_storage = $this->container->get('entity.manager')->getStorage('node');
|
||||
$this->config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save();
|
||||
$user_storage = $this->container->get('entity.manager')->getStorage('user');
|
||||
|
||||
// Create a user.
|
||||
$account = $this->drupalCreateUser(array());
|
||||
$account = $this->drupalCreateUser([]);
|
||||
$this->drupalLogin($account);
|
||||
// Load a real user object.
|
||||
$user_storage->resetCache(array($account->id()));
|
||||
$user_storage->resetCache([$account->id()]);
|
||||
$account = $user_storage->load($account->id());
|
||||
|
||||
// Create a node.
|
||||
$node = $this->drupalCreateNode(array('uid' => $account->id()));
|
||||
$node = $this->drupalCreateNode(['uid' => $account->id()]);
|
||||
|
||||
// Attempt to cancel account.
|
||||
$this->drupalGet('user/' . $account->id() . '/edit');
|
||||
|
@ -56,12 +56,12 @@ class UserCancelTest extends WebTestBase {
|
|||
$timestamp = $account->getLastLoginTime();
|
||||
$this->drupalGet("user/" . $account->id() . "/cancel/confirm/$timestamp/" . user_pass_rehash($account, $timestamp));
|
||||
$this->assertResponse(403, 'Bogus cancelling request rejected.');
|
||||
$user_storage->resetCache(array($account->id()));
|
||||
$user_storage->resetCache([$account->id()]);
|
||||
$account = $user_storage->load($account->id());
|
||||
$this->assertTrue($account->isActive(), 'User account was not canceled.');
|
||||
|
||||
// Confirm user's content has not been altered.
|
||||
$node_storage->resetCache(array($node->id()));
|
||||
$node_storage->resetCache([$node->id()]);
|
||||
$test_node = $node_storage->load($node->id());
|
||||
$this->assertTrue(($test_node->getOwnerId() == $account->id() && $test_node->isPublished()), 'Node of the user has not been altered.');
|
||||
}
|
||||
|
@ -70,21 +70,21 @@ class UserCancelTest extends WebTestBase {
|
|||
* Test ability to change the permission for canceling users.
|
||||
*/
|
||||
public function testUserCancelChangePermission() {
|
||||
\Drupal::service('module_installer')->install(array('user_form_test'));
|
||||
\Drupal::service('module_installer')->install(['user_form_test']);
|
||||
\Drupal::service('router.builder')->rebuild();
|
||||
$this->config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save();
|
||||
|
||||
// Create a regular user.
|
||||
$account = $this->drupalCreateUser(array());
|
||||
$account = $this->drupalCreateUser([]);
|
||||
|
||||
$admin_user = $this->drupalCreateUser(array('cancel other accounts'));
|
||||
$admin_user = $this->drupalCreateUser(['cancel other accounts']);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
// Delete regular user.
|
||||
$this->drupalPostForm('user_form_test_cancel/' . $account->id(), array(), t('Cancel account'));
|
||||
$this->drupalPostForm('user_form_test_cancel/' . $account->id(), [], t('Cancel account'));
|
||||
|
||||
// Confirm deletion.
|
||||
$this->assertRaw(t('%name has been deleted.', array('%name' => $account->getUsername())), 'User deleted.');
|
||||
$this->assertRaw(t('%name has been deleted.', ['%name' => $account->getUsername()]), 'User deleted.');
|
||||
$this->assertFalse(User::load($account->id()), 'User is not found in the database.');
|
||||
}
|
||||
|
||||
|
@ -94,17 +94,17 @@ class UserCancelTest extends WebTestBase {
|
|||
* This should never be possible, or the site owner would become unable to
|
||||
* administer the site.
|
||||
*/
|
||||
function testUserCancelUid1() {
|
||||
public function testUserCancelUid1() {
|
||||
$user_storage = $this->container->get('entity.manager')->getStorage('user');
|
||||
|
||||
\Drupal::service('module_installer')->install(array('views'));
|
||||
\Drupal::service('module_installer')->install(['views']);
|
||||
\Drupal::service('router.builder')->rebuild();
|
||||
// Update uid 1's name and password to we know it.
|
||||
$password = user_password();
|
||||
$account = array(
|
||||
$account = [
|
||||
'name' => 'user1',
|
||||
'pass' => $this->container->get('password')->hash(trim($password)),
|
||||
);
|
||||
];
|
||||
// We cannot use $account->save() here, because this would result in the
|
||||
// password being hashed again.
|
||||
db_update('users_field_data')
|
||||
|
@ -113,21 +113,21 @@ class UserCancelTest extends WebTestBase {
|
|||
->execute();
|
||||
|
||||
// Reload and log in uid 1.
|
||||
$user_storage->resetCache(array(1));
|
||||
$user_storage->resetCache([1]);
|
||||
$user1 = $user_storage->load(1);
|
||||
$user1->pass_raw = $password;
|
||||
|
||||
// Try to cancel uid 1's account with a different user.
|
||||
$admin_user = $this->drupalCreateUser(array('administer users'));
|
||||
$admin_user = $this->drupalCreateUser(['administer users']);
|
||||
$this->drupalLogin($admin_user);
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'action' => 'user_cancel_user_action',
|
||||
'user_bulk_form[0]' => TRUE,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/people', $edit, t('Apply to selected items'));
|
||||
|
||||
// Verify that uid 1's account was not cancelled.
|
||||
$user_storage->resetCache(array(1));
|
||||
$user_storage->resetCache([1]);
|
||||
$user1 = $user_storage->load(1);
|
||||
$this->assertTrue($user1->isActive(), 'User #1 still exists and is not blocked.');
|
||||
}
|
||||
|
@ -135,20 +135,20 @@ class UserCancelTest extends WebTestBase {
|
|||
/**
|
||||
* Attempt invalid account cancellations.
|
||||
*/
|
||||
function testUserCancelInvalid() {
|
||||
public function testUserCancelInvalid() {
|
||||
$node_storage = $this->container->get('entity.manager')->getStorage('node');
|
||||
$this->config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save();
|
||||
$user_storage = $this->container->get('entity.manager')->getStorage('user');
|
||||
|
||||
// Create a user.
|
||||
$account = $this->drupalCreateUser(array('cancel account'));
|
||||
$account = $this->drupalCreateUser(['cancel account']);
|
||||
$this->drupalLogin($account);
|
||||
// Load a real user object.
|
||||
$user_storage->resetCache(array($account->id()));
|
||||
$user_storage->resetCache([$account->id()]);
|
||||
$account = $user_storage->load($account->id());
|
||||
|
||||
// Create a node.
|
||||
$node = $this->drupalCreateNode(array('uid' => $account->id()));
|
||||
$node = $this->drupalCreateNode(['uid' => $account->id()]);
|
||||
|
||||
// Attempt to cancel account.
|
||||
$this->drupalPostForm('user/' . $account->id() . '/edit', NULL, t('Cancel account'));
|
||||
|
@ -162,7 +162,7 @@ class UserCancelTest extends WebTestBase {
|
|||
$bogus_timestamp = $timestamp + 60;
|
||||
$this->drupalGet("user/" . $account->id() . "/cancel/confirm/$bogus_timestamp/" . user_pass_rehash($account, $bogus_timestamp));
|
||||
$this->assertText(t('You have tried to use an account cancellation link that has expired. Please request a new one using the form below.'), 'Bogus cancelling request rejected.');
|
||||
$user_storage->resetCache(array($account->id()));
|
||||
$user_storage->resetCache([$account->id()]);
|
||||
$account = $user_storage->load($account->id());
|
||||
$this->assertTrue($account->isActive(), 'User account was not canceled.');
|
||||
|
||||
|
@ -170,12 +170,12 @@ class UserCancelTest extends WebTestBase {
|
|||
$bogus_timestamp = $timestamp - 86400 - 60;
|
||||
$this->drupalGet("user/" . $account->id() . "/cancel/confirm/$bogus_timestamp/" . user_pass_rehash($account, $bogus_timestamp));
|
||||
$this->assertText(t('You have tried to use an account cancellation link that has expired. Please request a new one using the form below.'), 'Expired cancel account request rejected.');
|
||||
$user_storage->resetCache(array($account->id()));
|
||||
$user_storage->resetCache([$account->id()]);
|
||||
$account = $user_storage->load($account->id());
|
||||
$this->assertTrue($account->isActive(), 'User account was not canceled.');
|
||||
|
||||
// Confirm user's content has not been altered.
|
||||
$node_storage->resetCache(array($node->id()));
|
||||
$node_storage->resetCache([$node->id()]);
|
||||
$test_node = $node_storage->load($node->id());
|
||||
$this->assertTrue(($test_node->getOwnerId() == $account->id() && $test_node->isPublished()), 'Node of the user has not been altered.');
|
||||
}
|
||||
|
@ -183,16 +183,16 @@ class UserCancelTest extends WebTestBase {
|
|||
/**
|
||||
* Disable account and keep all content.
|
||||
*/
|
||||
function testUserBlock() {
|
||||
public function testUserBlock() {
|
||||
$this->config('user.settings')->set('cancel_method', 'user_cancel_block')->save();
|
||||
$user_storage = $this->container->get('entity.manager')->getStorage('user');
|
||||
|
||||
// Create a user.
|
||||
$web_user = $this->drupalCreateUser(array('cancel account'));
|
||||
$web_user = $this->drupalCreateUser(['cancel account']);
|
||||
$this->drupalLogin($web_user);
|
||||
|
||||
// Load a real user object.
|
||||
$user_storage->resetCache(array($web_user->id()));
|
||||
$user_storage->resetCache([$web_user->id()]);
|
||||
$account = $user_storage->load($web_user->id());
|
||||
|
||||
// Attempt to cancel account.
|
||||
|
@ -210,18 +210,18 @@ class UserCancelTest extends WebTestBase {
|
|||
|
||||
// Confirm account cancellation request.
|
||||
$this->drupalGet("user/" . $account->id() . "/cancel/confirm/$timestamp/" . user_pass_rehash($account, $timestamp));
|
||||
$user_storage->resetCache(array($account->id()));
|
||||
$user_storage->resetCache([$account->id()]);
|
||||
$account = $user_storage->load($account->id());
|
||||
$this->assertTrue($account->isBlocked(), 'User has been blocked.');
|
||||
|
||||
// Confirm that the confirmation message made it through to the end user.
|
||||
$this->assertRaw(t('%name has been disabled.', array('%name' => $account->getUsername())), "Confirmation message displayed to user.");
|
||||
$this->assertRaw(t('%name has been disabled.', ['%name' => $account->getUsername()]), "Confirmation message displayed to user.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable account and unpublish all content.
|
||||
*/
|
||||
function testUserBlockUnpublish() {
|
||||
public function testUserBlockUnpublish() {
|
||||
$node_storage = $this->container->get('entity.manager')->getStorage('node');
|
||||
$this->config('user.settings')->set('cancel_method', 'user_cancel_block_unpublish')->save();
|
||||
// Create comment field on page.
|
||||
|
@ -229,14 +229,14 @@ class UserCancelTest extends WebTestBase {
|
|||
$user_storage = $this->container->get('entity.manager')->getStorage('user');
|
||||
|
||||
// Create a user.
|
||||
$account = $this->drupalCreateUser(array('cancel account'));
|
||||
$account = $this->drupalCreateUser(['cancel account']);
|
||||
$this->drupalLogin($account);
|
||||
// Load a real user object.
|
||||
$user_storage->resetCache(array($account->id()));
|
||||
$user_storage->resetCache([$account->id()]);
|
||||
$account = $user_storage->load($account->id());
|
||||
|
||||
// Create a node with two revisions.
|
||||
$node = $this->drupalCreateNode(array('uid' => $account->id()));
|
||||
$node = $this->drupalCreateNode(['uid' => $account->id()]);
|
||||
$settings = get_object_vars($node);
|
||||
$settings['revision'] = 1;
|
||||
$node = $this->drupalCreateNode($settings);
|
||||
|
@ -244,7 +244,7 @@ class UserCancelTest extends WebTestBase {
|
|||
// Add a comment to the page.
|
||||
$comment_subject = $this->randomMachineName(8);
|
||||
$comment_body = $this->randomMachineName(8);
|
||||
$comment = Comment::create(array(
|
||||
$comment = Comment::create([
|
||||
'subject' => $comment_subject,
|
||||
'comment_body' => $comment_body,
|
||||
'entity_id' => $node->id(),
|
||||
|
@ -252,7 +252,7 @@ class UserCancelTest extends WebTestBase {
|
|||
'field_name' => 'comment',
|
||||
'status' => CommentInterface::PUBLISHED,
|
||||
'uid' => $account->id(),
|
||||
));
|
||||
]);
|
||||
$comment->save();
|
||||
|
||||
// Attempt to cancel account.
|
||||
|
@ -268,30 +268,30 @@ class UserCancelTest extends WebTestBase {
|
|||
|
||||
// Confirm account cancellation request.
|
||||
$this->drupalGet("user/" . $account->id() . "/cancel/confirm/$timestamp/" . user_pass_rehash($account, $timestamp));
|
||||
$user_storage->resetCache(array($account->id()));
|
||||
$user_storage->resetCache([$account->id()]);
|
||||
$account = $user_storage->load($account->id());
|
||||
$this->assertTrue($account->isBlocked(), 'User has been blocked.');
|
||||
|
||||
// Confirm user's content has been unpublished.
|
||||
$node_storage->resetCache(array($node->id()));
|
||||
$node_storage->resetCache([$node->id()]);
|
||||
$test_node = $node_storage->load($node->id());
|
||||
$this->assertFalse($test_node->isPublished(), 'Node of the user has been unpublished.');
|
||||
$test_node = node_revision_load($node->getRevisionId());
|
||||
$this->assertFalse($test_node->isPublished(), 'Node revision of the user has been unpublished.');
|
||||
|
||||
$storage = \Drupal::entityManager()->getStorage('comment');
|
||||
$storage->resetCache(array($comment->id()));
|
||||
$storage->resetCache([$comment->id()]);
|
||||
$comment = $storage->load($comment->id());
|
||||
$this->assertFalse($comment->isPublished(), 'Comment of the user has been unpublished.');
|
||||
|
||||
// Confirm that the confirmation message made it through to the end user.
|
||||
$this->assertRaw(t('%name has been disabled.', array('%name' => $account->getUsername())), "Confirmation message displayed to user.");
|
||||
$this->assertRaw(t('%name has been disabled.', ['%name' => $account->getUsername()]), "Confirmation message displayed to user.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete account and anonymize all content.
|
||||
*/
|
||||
function testUserAnonymize() {
|
||||
public function testUserAnonymize() {
|
||||
$node_storage = $this->container->get('entity.manager')->getStorage('node');
|
||||
$this->config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save();
|
||||
// Create comment field on page.
|
||||
|
@ -299,19 +299,19 @@ class UserCancelTest extends WebTestBase {
|
|||
$user_storage = $this->container->get('entity.manager')->getStorage('user');
|
||||
|
||||
// Create a user.
|
||||
$account = $this->drupalCreateUser(array('cancel account'));
|
||||
$account = $this->drupalCreateUser(['cancel account']);
|
||||
$this->drupalLogin($account);
|
||||
// Load a real user object.
|
||||
$user_storage->resetCache(array($account->id()));
|
||||
$user_storage->resetCache([$account->id()]);
|
||||
$account = $user_storage->load($account->id());
|
||||
|
||||
// Create a simple node.
|
||||
$node = $this->drupalCreateNode(array('uid' => $account->id()));
|
||||
$node = $this->drupalCreateNode(['uid' => $account->id()]);
|
||||
|
||||
// Add a comment to the page.
|
||||
$comment_subject = $this->randomMachineName(8);
|
||||
$comment_body = $this->randomMachineName(8);
|
||||
$comment = Comment::create(array(
|
||||
$comment = Comment::create([
|
||||
'subject' => $comment_subject,
|
||||
'comment_body' => $comment_body,
|
||||
'entity_id' => $node->id(),
|
||||
|
@ -319,12 +319,12 @@ class UserCancelTest extends WebTestBase {
|
|||
'field_name' => 'comment',
|
||||
'status' => CommentInterface::PUBLISHED,
|
||||
'uid' => $account->id(),
|
||||
));
|
||||
]);
|
||||
$comment->save();
|
||||
|
||||
// Create a node with two revisions, the initial one belonging to the
|
||||
// cancelling user.
|
||||
$revision_node = $this->drupalCreateNode(array('uid' => $account->id()));
|
||||
$revision_node = $this->drupalCreateNode(['uid' => $account->id()]);
|
||||
$revision = $revision_node->getRevisionId();
|
||||
$settings = get_object_vars($revision_node);
|
||||
$settings['revision'] = 1;
|
||||
|
@ -335,7 +335,7 @@ class UserCancelTest extends WebTestBase {
|
|||
$this->drupalGet('user/' . $account->id() . '/edit');
|
||||
$this->drupalPostForm(NULL, NULL, t('Cancel account'));
|
||||
$this->assertText(t('Are you sure you want to cancel your account?'), 'Confirmation form to cancel account displayed.');
|
||||
$this->assertRaw(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' => $this->config('user.settings')->get('anonymous'))), 'Informs that all content will be attributed to anonymous account.');
|
||||
$this->assertRaw(t('Your account will be removed and all account information deleted. All of your content will be assigned to the %anonymous-name user.', ['%anonymous-name' => $this->config('user.settings')->get('anonymous')]), 'Informs that all content will be attributed to anonymous account.');
|
||||
|
||||
// Confirm account cancellation.
|
||||
$timestamp = time();
|
||||
|
@ -344,28 +344,28 @@ class UserCancelTest extends WebTestBase {
|
|||
|
||||
// Confirm account cancellation request.
|
||||
$this->drupalGet("user/" . $account->id() . "/cancel/confirm/$timestamp/" . user_pass_rehash($account, $timestamp));
|
||||
$user_storage->resetCache(array($account->id()));
|
||||
$user_storage->resetCache([$account->id()]);
|
||||
$this->assertFalse($user_storage->load($account->id()), 'User is not found in the database.');
|
||||
|
||||
// Confirm that user's content has been attributed to anonymous user.
|
||||
$anonymous_user = User::getAnonymousUser();
|
||||
$node_storage->resetCache(array($node->id()));
|
||||
$node_storage->resetCache([$node->id()]);
|
||||
$test_node = $node_storage->load($node->id());
|
||||
$this->assertTrue(($test_node->getOwnerId() == 0 && $test_node->isPublished()), 'Node of the user has been attributed to anonymous user.');
|
||||
$test_node = node_revision_load($revision, TRUE);
|
||||
$this->assertTrue(($test_node->getRevisionUser()->id() == 0 && $test_node->isPublished()), 'Node revision of the user has been attributed to anonymous user.');
|
||||
$node_storage->resetCache(array($revision_node->id()));
|
||||
$node_storage->resetCache([$revision_node->id()]);
|
||||
$test_node = $node_storage->load($revision_node->id());
|
||||
$this->assertTrue(($test_node->getOwnerId() != 0 && $test_node->isPublished()), "Current revision of the user's node was not attributed to anonymous user.");
|
||||
|
||||
$storage = \Drupal::entityManager()->getStorage('comment');
|
||||
$storage->resetCache(array($comment->id()));
|
||||
$storage->resetCache([$comment->id()]);
|
||||
$test_comment = $storage->load($comment->id());
|
||||
$this->assertTrue(($test_comment->getOwnerId() == 0 && $test_comment->isPublished()), 'Comment of the user has been attributed to anonymous user.');
|
||||
$this->assertEqual($test_comment->getAuthorName(), $anonymous_user->getDisplayName(), 'Comment of the user has been attributed to anonymous user name.');
|
||||
|
||||
// Confirm that the confirmation message made it through to the end user.
|
||||
$this->assertRaw(t('%name has been deleted.', array('%name' => $account->getUsername())), "Confirmation message displayed to user.");
|
||||
$this->assertRaw(t('%name has been deleted.', ['%name' => $account->getUsername()]), "Confirmation message displayed to user.");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -377,7 +377,7 @@ class UserCancelTest extends WebTestBase {
|
|||
$user_storage = $this->container->get('entity.manager')->getStorage('user');
|
||||
|
||||
// Create a user.
|
||||
$account = $this->drupalCreateUser(array('cancel account'));
|
||||
$account = $this->drupalCreateUser(['cancel account']);
|
||||
$this->drupalLogin($account);
|
||||
// Load a real user object.
|
||||
$user_storage->resetCache([$account->id()]);
|
||||
|
@ -395,7 +395,7 @@ class UserCancelTest extends WebTestBase {
|
|||
$this->drupalGet('user/' . $account->id() . '/edit');
|
||||
$this->drupalPostForm(NULL, NULL, t('Cancel account'));
|
||||
$this->assertText(t('Are you sure you want to cancel your account?'), 'Confirmation form to cancel account displayed.');
|
||||
$this->assertRaw(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' => $this->config('user.settings')->get('anonymous'))), 'Informs that all content will be attributed to anonymous account.');
|
||||
$this->assertRaw(t('Your account will be removed and all account information deleted. All of your content will be assigned to the %anonymous-name user.', ['%anonymous-name' => $this->config('user.settings')->get('anonymous')]), 'Informs that all content will be attributed to anonymous account.');
|
||||
|
||||
// Confirm account cancellation.
|
||||
$timestamp = time();
|
||||
|
@ -418,39 +418,39 @@ class UserCancelTest extends WebTestBase {
|
|||
/**
|
||||
* Delete account and remove all content.
|
||||
*/
|
||||
function testUserDelete() {
|
||||
public function testUserDelete() {
|
||||
$node_storage = $this->container->get('entity.manager')->getStorage('node');
|
||||
$this->config('user.settings')->set('cancel_method', 'user_cancel_delete')->save();
|
||||
\Drupal::service('module_installer')->install(array('comment'));
|
||||
\Drupal::service('module_installer')->install(['comment']);
|
||||
$this->resetAll();
|
||||
$this->addDefaultCommentField('node', 'page');
|
||||
$user_storage = $this->container->get('entity.manager')->getStorage('user');
|
||||
|
||||
// Create a user.
|
||||
$account = $this->drupalCreateUser(array('cancel account', 'post comments', 'skip comment approval'));
|
||||
$account = $this->drupalCreateUser(['cancel account', 'post comments', 'skip comment approval']);
|
||||
$this->drupalLogin($account);
|
||||
// Load a real user object.
|
||||
$user_storage->resetCache(array($account->id()));
|
||||
$user_storage->resetCache([$account->id()]);
|
||||
$account = $user_storage->load($account->id());
|
||||
|
||||
// Create a simple node.
|
||||
$node = $this->drupalCreateNode(array('uid' => $account->id()));
|
||||
$node = $this->drupalCreateNode(['uid' => $account->id()]);
|
||||
|
||||
// Create comment.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['subject[0][value]'] = $this->randomMachineName(8);
|
||||
$edit['comment_body[0][value]'] = $this->randomMachineName(16);
|
||||
|
||||
$this->drupalPostForm('comment/reply/node/' . $node->id() . '/comment', $edit, t('Preview'));
|
||||
$this->drupalPostForm(NULL, array(), t('Save'));
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
$this->assertText(t('Your comment has been posted.'));
|
||||
$comments = entity_load_multiple_by_properties('comment', array('subject' => $edit['subject[0][value]']));
|
||||
$comments = entity_load_multiple_by_properties('comment', ['subject' => $edit['subject[0][value]']]);
|
||||
$comment = reset($comments);
|
||||
$this->assertTrue($comment->id(), 'Comment found.');
|
||||
|
||||
// Create a node with two revisions, the initial one belonging to the
|
||||
// cancelling user.
|
||||
$revision_node = $this->drupalCreateNode(array('uid' => $account->id()));
|
||||
$revision_node = $this->drupalCreateNode(['uid' => $account->id()]);
|
||||
$revision = $revision_node->getRevisionId();
|
||||
$settings = get_object_vars($revision_node);
|
||||
$settings['revision'] = 1;
|
||||
|
@ -470,80 +470,80 @@ class UserCancelTest extends WebTestBase {
|
|||
|
||||
// Confirm account cancellation request.
|
||||
$this->drupalGet("user/" . $account->id() . "/cancel/confirm/$timestamp/" . user_pass_rehash($account, $timestamp));
|
||||
$user_storage->resetCache(array($account->id()));
|
||||
$user_storage->resetCache([$account->id()]);
|
||||
$this->assertFalse($user_storage->load($account->id()), 'User is not found in the database.');
|
||||
|
||||
// Confirm that user's content has been deleted.
|
||||
$node_storage->resetCache(array($node->id()));
|
||||
$node_storage->resetCache([$node->id()]);
|
||||
$this->assertFalse($node_storage->load($node->id()), 'Node of the user has been deleted.');
|
||||
$this->assertFalse(node_revision_load($revision), 'Node revision of the user has been deleted.');
|
||||
$node_storage->resetCache(array($revision_node->id()));
|
||||
$node_storage->resetCache([$revision_node->id()]);
|
||||
$this->assertTrue($node_storage->load($revision_node->id()), "Current revision of the user's node was not deleted.");
|
||||
\Drupal::entityManager()->getStorage('comment')->resetCache(array($comment->id()));
|
||||
\Drupal::entityManager()->getStorage('comment')->resetCache([$comment->id()]);
|
||||
$this->assertFalse(Comment::load($comment->id()), 'Comment of the user has been deleted.');
|
||||
|
||||
// Confirm that the confirmation message made it through to the end user.
|
||||
$this->assertRaw(t('%name has been deleted.', array('%name' => $account->getUsername())), "Confirmation message displayed to user.");
|
||||
$this->assertRaw(t('%name has been deleted.', ['%name' => $account->getUsername()]), "Confirmation message displayed to user.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an administrative user and delete another user.
|
||||
*/
|
||||
function testUserCancelByAdmin() {
|
||||
public function testUserCancelByAdmin() {
|
||||
$this->config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save();
|
||||
|
||||
// Create a regular user.
|
||||
$account = $this->drupalCreateUser(array());
|
||||
$account = $this->drupalCreateUser([]);
|
||||
|
||||
// Create administrative user.
|
||||
$admin_user = $this->drupalCreateUser(array('administer users'));
|
||||
$admin_user = $this->drupalCreateUser(['administer users']);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
// Delete regular user.
|
||||
$this->drupalGet('user/' . $account->id() . '/edit');
|
||||
$this->drupalPostForm(NULL, NULL, t('Cancel account'));
|
||||
$this->assertRaw(t('Are you sure you want to cancel the account %name?', array('%name' => $account->getUsername())), 'Confirmation form to cancel account displayed.');
|
||||
$this->assertRaw(t('Are you sure you want to cancel the account %name?', ['%name' => $account->getUsername()]), 'Confirmation form to cancel account displayed.');
|
||||
$this->assertText(t('Select the method to cancel the account above.'), 'Allows to select account cancellation method.');
|
||||
|
||||
// Confirm deletion.
|
||||
$this->drupalPostForm(NULL, NULL, t('Cancel account'));
|
||||
$this->assertRaw(t('%name has been deleted.', array('%name' => $account->getUsername())), 'User deleted.');
|
||||
$this->assertRaw(t('%name has been deleted.', ['%name' => $account->getUsername()]), 'User deleted.');
|
||||
$this->assertFalse(User::load($account->id()), 'User is not found in the database.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests deletion of a user account without an email address.
|
||||
*/
|
||||
function testUserWithoutEmailCancelByAdmin() {
|
||||
public function testUserWithoutEmailCancelByAdmin() {
|
||||
$this->config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save();
|
||||
|
||||
// Create a regular user.
|
||||
$account = $this->drupalCreateUser(array());
|
||||
$account = $this->drupalCreateUser([]);
|
||||
// This user has no email address.
|
||||
$account->mail = '';
|
||||
$account->save();
|
||||
|
||||
// Create administrative user.
|
||||
$admin_user = $this->drupalCreateUser(array('administer users'));
|
||||
$admin_user = $this->drupalCreateUser(['administer users']);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
// Delete regular user without email address.
|
||||
$this->drupalGet('user/' . $account->id() . '/edit');
|
||||
$this->drupalPostForm(NULL, NULL, t('Cancel account'));
|
||||
$this->assertRaw(t('Are you sure you want to cancel the account %name?', array('%name' => $account->getUsername())), 'Confirmation form to cancel account displayed.');
|
||||
$this->assertRaw(t('Are you sure you want to cancel the account %name?', ['%name' => $account->getUsername()]), 'Confirmation form to cancel account displayed.');
|
||||
$this->assertText(t('Select the method to cancel the account above.'), 'Allows to select account cancellation method.');
|
||||
|
||||
// Confirm deletion.
|
||||
$this->drupalPostForm(NULL, NULL, t('Cancel account'));
|
||||
$this->assertRaw(t('%name has been deleted.', array('%name' => $account->getUsername())), 'User deleted.');
|
||||
$this->assertRaw(t('%name has been deleted.', ['%name' => $account->getUsername()]), 'User deleted.');
|
||||
$this->assertFalse(User::load($account->id()), 'User is not found in the database.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an administrative user and mass-delete other users.
|
||||
*/
|
||||
function testMassUserCancelByAdmin() {
|
||||
\Drupal::service('module_installer')->install(array('views'));
|
||||
public function testMassUserCancelByAdmin() {
|
||||
\Drupal::service('module_installer')->install(['views']);
|
||||
\Drupal::service('router.builder')->rebuild();
|
||||
$this->config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save();
|
||||
$user_storage = $this->container->get('entity.manager')->getStorage('user');
|
||||
|
@ -551,18 +551,18 @@ class UserCancelTest extends WebTestBase {
|
|||
$this->config('user.settings')->set('notify.status_canceled', TRUE)->save();
|
||||
|
||||
// Create administrative user.
|
||||
$admin_user = $this->drupalCreateUser(array('administer users'));
|
||||
$admin_user = $this->drupalCreateUser(['administer users']);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
// Create some users.
|
||||
$users = array();
|
||||
$users = [];
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$account = $this->drupalCreateUser(array());
|
||||
$account = $this->drupalCreateUser([]);
|
||||
$users[$account->id()] = $account;
|
||||
}
|
||||
|
||||
// Cancel user accounts, including own one.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['action'] = 'user_cancel_user_action';
|
||||
for ($i = 0; $i <= 4; $i++) {
|
||||
$edit['user_bulk_form[' . $i . ']'] = TRUE;
|
||||
|
@ -578,7 +578,7 @@ class UserCancelTest extends WebTestBase {
|
|||
$status = TRUE;
|
||||
foreach ($users as $account) {
|
||||
$status = $status && (strpos($this->content, $account->getUsername() . '</em> has been deleted.') !== FALSE);
|
||||
$user_storage->resetCache(array($account->id()));
|
||||
$user_storage->resetCache([$account->id()]);
|
||||
$status = $status && !$user_storage->load($account->id());
|
||||
}
|
||||
$this->assertTrue($status, 'Users deleted and not found in the database.');
|
||||
|
@ -589,9 +589,25 @@ class UserCancelTest extends WebTestBase {
|
|||
$this->assertTrue($admin_user->isActive(), 'Administrative user is found in the database and enabled.');
|
||||
|
||||
// Verify that uid 1's account was not cancelled.
|
||||
$user_storage->resetCache(array(1));
|
||||
$user_storage->resetCache([1]);
|
||||
$user1 = $user_storage->load(1);
|
||||
$this->assertTrue($user1->isActive(), 'User #1 still exists and is not blocked.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests user cancel with node access.
|
||||
*/
|
||||
public function testUserDeleteWithContentAndNodeAccess() {
|
||||
|
||||
\Drupal::service('module_installer')->install(['node_access_test']);
|
||||
// Rebuild node access.
|
||||
node_access_rebuild();
|
||||
|
||||
$account = $this->drupalCreateUser(['access content']);
|
||||
$node = $this->drupalCreateNode(['type' => 'page', 'uid' => $account->id()]);
|
||||
$account->delete();
|
||||
$load2 = \Drupal::entityTypeManager()->getStorage('node')->load($node->id());
|
||||
$this->assertTrue(empty($load2));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,14 +18,14 @@ class UserCreateTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('image');
|
||||
public static $modules = ['image'];
|
||||
|
||||
/**
|
||||
* Create a user through the administration interface and ensure that it
|
||||
* displays in the user list.
|
||||
*/
|
||||
public function testUserAdd() {
|
||||
$user = $this->drupalCreateUser(array('administer users'));
|
||||
$user = $this->drupalCreateUser(['administer users']);
|
||||
$this->drupalLogin($user);
|
||||
|
||||
$this->assertEqual($user->getCreatedTime(), REQUEST_TIME, 'Creating a user sets default "created" timestamp.');
|
||||
|
@ -33,18 +33,18 @@ class UserCreateTest extends WebTestBase {
|
|||
|
||||
// Create a field.
|
||||
$field_name = 'test_field';
|
||||
FieldStorageConfig::create(array(
|
||||
FieldStorageConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'user',
|
||||
'module' => 'image',
|
||||
'type' => 'image',
|
||||
'cardinality' => 1,
|
||||
'locked' => FALSE,
|
||||
'indexes' => array('target_id' => array('target_id')),
|
||||
'settings' => array(
|
||||
'indexes' => ['target_id' => ['target_id']],
|
||||
'settings' => [
|
||||
'uri_scheme' => 'public',
|
||||
),
|
||||
))->save();
|
||||
],
|
||||
])->save();
|
||||
|
||||
FieldConfig::create([
|
||||
'field_name' => $field_name,
|
||||
|
@ -53,7 +53,7 @@ class UserCreateTest extends WebTestBase {
|
|||
'bundle' => 'user',
|
||||
'description' => t('Your virtual face or picture.'),
|
||||
'required' => FALSE,
|
||||
'settings' => array(
|
||||
'settings' => [
|
||||
'file_extensions' => 'png gif jpg jpeg',
|
||||
'file_directory' => 'pictures',
|
||||
'max_filesize' => '30 KB',
|
||||
|
@ -61,7 +61,7 @@ class UserCreateTest extends WebTestBase {
|
|||
'title_field' => 0,
|
||||
'max_resolution' => '85x85',
|
||||
'min_resolution' => '',
|
||||
),
|
||||
],
|
||||
])->save();
|
||||
|
||||
// Test user creation page for valid fields.
|
||||
|
@ -86,23 +86,23 @@ class UserCreateTest extends WebTestBase {
|
|||
|
||||
// We create two users, notifying one and not notifying the other, to
|
||||
// ensure that the tests work in both cases.
|
||||
foreach (array(FALSE, TRUE) as $notify) {
|
||||
foreach ([FALSE, TRUE] as $notify) {
|
||||
$name = $this->randomMachineName();
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'name' => $name,
|
||||
'mail' => $this->randomMachineName() . '@example.com',
|
||||
'pass[pass1]' => $pass = $this->randomString(),
|
||||
'pass[pass2]' => $pass,
|
||||
'notify' => $notify,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/people/create', $edit, t('Create new account'));
|
||||
|
||||
if ($notify) {
|
||||
$this->assertText(t('A welcome message with further instructions has been emailed to the new user @name.', array('@name' => $edit['name'])), 'User created');
|
||||
$this->assertText(t('A welcome message with further instructions has been emailed to the new user @name.', ['@name' => $edit['name']]), 'User created');
|
||||
$this->assertEqual(count($this->drupalGetMails()), 1, 'Notification email sent');
|
||||
}
|
||||
else {
|
||||
$this->assertText(t('Created a new user account for @name. No email has been sent.', array('@name' => $edit['name'])), 'User created');
|
||||
$this->assertText(t('Created a new user account for @name. No email has been sent.', ['@name' => $edit['name']]), 'User created');
|
||||
$this->assertEqual(count($this->drupalGetMails()), 0, 'Notification email not sent');
|
||||
}
|
||||
|
||||
|
@ -115,13 +115,13 @@ class UserCreateTest extends WebTestBase {
|
|||
// Test that the password '0' is considered a password.
|
||||
// @see https://www.drupal.org/node/2563751.
|
||||
$name = $this->randomMachineName();
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'name' => $name,
|
||||
'mail' => $this->randomMachineName() . '@example.com',
|
||||
'pass[pass1]' => 0,
|
||||
'pass[pass2]' => 0,
|
||||
'notify' => FALSE,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/people/create', $edit, t('Create new account'));
|
||||
$this->assertText("Created a new user account for $name. No email has been sent");
|
||||
$this->assertNoText('Password field is required');
|
||||
|
|
|
@ -14,19 +14,26 @@ class UserEditTest extends WebTestBase {
|
|||
/**
|
||||
* Test user edit page.
|
||||
*/
|
||||
function testUserEdit() {
|
||||
public function testUserEdit() {
|
||||
// Test user edit functionality.
|
||||
$user1 = $this->drupalCreateUser(array('change own username'));
|
||||
$user2 = $this->drupalCreateUser(array());
|
||||
$user1 = $this->drupalCreateUser(['change own username']);
|
||||
$user2 = $this->drupalCreateUser([]);
|
||||
$this->drupalLogin($user1);
|
||||
|
||||
// Test that error message appears when attempting to use a non-unique user name.
|
||||
$edit['name'] = $user2->getUsername();
|
||||
$this->drupalPostForm("user/" . $user1->id() . "/edit", $edit, t('Save'));
|
||||
$this->assertRaw(t('The username %name is already taken.', array('%name' => $edit['name'])));
|
||||
$this->assertRaw(t('The username %name is already taken.', ['%name' => $edit['name']]));
|
||||
|
||||
// Check that the default value in user name field
|
||||
// is the raw value and not a formatted one.
|
||||
\Drupal::state()->set('user_hooks_test_user_format_name_alter', TRUE);
|
||||
\Drupal::service('module_installer')->install(['user_hooks_test']);
|
||||
$this->drupalGet('user/' . $user1->id() . '/edit');
|
||||
$this->assertFieldByName('name', $user1->getAccountName());
|
||||
|
||||
// Check that filling out a single password field does not validate.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['pass[pass1]'] = '';
|
||||
$edit['pass[pass2]'] = $this->randomMachineName();
|
||||
$this->drupalPostForm("user/" . $user1->id() . "/edit", $edit, t('Save'));
|
||||
|
@ -39,21 +46,21 @@ class UserEditTest extends WebTestBase {
|
|||
|
||||
// Test that the error message appears when attempting to change the mail or
|
||||
// pass without the current password.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['mail'] = $this->randomMachineName() . '@new.example.com';
|
||||
$this->drupalPostForm("user/" . $user1->id() . "/edit", $edit, t('Save'));
|
||||
$this->assertRaw(t("Your current password is missing or incorrect; it's required to change the %name.", array('%name' => t('Email'))));
|
||||
$this->assertRaw(t("Your current password is missing or incorrect; it's required to change the %name.", ['%name' => t('Email')]));
|
||||
|
||||
$edit['current_pass'] = $user1->pass_raw;
|
||||
$this->drupalPostForm("user/" . $user1->id() . "/edit", $edit, t('Save'));
|
||||
$this->assertRaw(t("The changes have been saved."));
|
||||
|
||||
// Test that the user must enter current password before changing passwords.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['pass[pass1]'] = $new_pass = $this->randomMachineName();
|
||||
$edit['pass[pass2]'] = $new_pass;
|
||||
$this->drupalPostForm("user/" . $user1->id() . "/edit", $edit, t('Save'));
|
||||
$this->assertRaw(t("Your current password is missing or incorrect; it's required to change the %name.", array('%name' => t('Password'))));
|
||||
$this->assertRaw(t("Your current password is missing or incorrect; it's required to change the %name.", ['%name' => t('Password')]));
|
||||
|
||||
// Try again with the current password.
|
||||
$edit['current_pass'] = $user1->pass_raw;
|
||||
|
@ -83,20 +90,20 @@ class UserEditTest extends WebTestBase {
|
|||
|
||||
// Check that the user status field has the correct value and that it is
|
||||
// properly displayed.
|
||||
$admin_user = $this->drupalCreateUser(array('administer users'));
|
||||
$admin_user = $this->drupalCreateUser(['administer users']);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
$this->drupalGet('user/' . $user1->id() . '/edit');
|
||||
$this->assertNoFieldChecked('edit-status-0');
|
||||
$this->assertFieldChecked('edit-status-1');
|
||||
|
||||
$edit = array('status' => 0);
|
||||
$edit = ['status' => 0];
|
||||
$this->drupalPostForm('user/' . $user1->id() . '/edit', $edit, t('Save'));
|
||||
$this->assertText(t('The changes have been saved.'));
|
||||
$this->assertFieldChecked('edit-status-0');
|
||||
$this->assertNoFieldChecked('edit-status-1');
|
||||
|
||||
$edit = array('status' => 1);
|
||||
$edit = ['status' => 1];
|
||||
$this->drupalPostForm('user/' . $user1->id() . '/edit', $edit, t('Save'));
|
||||
$this->assertText(t('The changes have been saved.'));
|
||||
$this->assertNoFieldChecked('edit-status-0');
|
||||
|
@ -124,16 +131,16 @@ class UserEditTest extends WebTestBase {
|
|||
/**
|
||||
* Tests editing of a user account without an email address.
|
||||
*/
|
||||
function testUserWithoutEmailEdit() {
|
||||
public function testUserWithoutEmailEdit() {
|
||||
// Test that an admin can edit users without an email address.
|
||||
$admin = $this->drupalCreateUser(array('administer users'));
|
||||
$admin = $this->drupalCreateUser(['administer users']);
|
||||
$this->drupalLogin($admin);
|
||||
// Create a regular user.
|
||||
$user1 = $this->drupalCreateUser(array());
|
||||
$user1 = $this->drupalCreateUser([]);
|
||||
// This user has no email address.
|
||||
$user1->mail = '';
|
||||
$user1->save();
|
||||
$this->drupalPostForm("user/" . $user1->id() . "/edit", array('mail' => ''), t('Save'));
|
||||
$this->drupalPostForm("user/" . $user1->id() . "/edit", ['mail' => ''], t('Save'));
|
||||
$this->assertRaw(t("The changes have been saved."));
|
||||
}
|
||||
|
||||
|
|
|
@ -18,14 +18,14 @@ class UserLanguageCreationTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('user', 'language');
|
||||
public static $modules = ['user', 'language'];
|
||||
|
||||
/**
|
||||
* Functional test for language handling during user creation.
|
||||
*/
|
||||
function testLocalUserCreation() {
|
||||
public function testLocalUserCreation() {
|
||||
// User to add and remove language and create new users.
|
||||
$admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages', 'administer users'));
|
||||
$admin_user = $this->drupalCreateUser(['administer languages', 'access administration pages', 'administer users']);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
// Add predefined language.
|
||||
|
@ -33,9 +33,9 @@ class UserLanguageCreationTest extends WebTestBase {
|
|||
ConfigurableLanguage::createFromLangcode($langcode)->save();
|
||||
|
||||
// Set language negotiation.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'language_interface[enabled][language-url]' => TRUE,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
|
||||
$this->assertText(t('Language detection configuration saved.'), 'Set language negotiation.');
|
||||
|
||||
|
@ -47,12 +47,12 @@ class UserLanguageCreationTest extends WebTestBase {
|
|||
// Create a user with the admin/people/create form and check if the correct
|
||||
// language is set.
|
||||
$username = $this->randomMachineName(10);
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'name' => $username,
|
||||
'mail' => $this->randomMachineName(4) . '@example.com',
|
||||
'pass[pass1]' => $username,
|
||||
'pass[pass2]' => $username,
|
||||
);
|
||||
];
|
||||
|
||||
$this->drupalPostForm($langcode . '/admin/people/create', $edit, t('Create new account'));
|
||||
|
||||
|
@ -67,10 +67,10 @@ class UserLanguageCreationTest extends WebTestBase {
|
|||
$this->assertNoFieldByName('language[fr]', 'Language selector is not accessible.');
|
||||
|
||||
$username = $this->randomMachineName(10);
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'name' => $username,
|
||||
'mail' => $this->randomMachineName(4) . '@example.com',
|
||||
);
|
||||
];
|
||||
|
||||
$this->drupalPostForm($langcode . '/user/register', $edit, t('Create new account'));
|
||||
|
||||
|
@ -88,10 +88,10 @@ class UserLanguageCreationTest extends WebTestBase {
|
|||
|
||||
// Set pass_raw so we can log in the new user.
|
||||
$user->pass_raw = $this->randomMachineName(10);
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'pass[pass1]' => $user->pass_raw,
|
||||
'pass[pass2]' => $user->pass_raw,
|
||||
);
|
||||
];
|
||||
|
||||
$this->drupalPostForm($user_edit, $edit, t('Save'));
|
||||
|
||||
|
|
|
@ -15,15 +15,15 @@ class UserLoginTest extends WebTestBase {
|
|||
/**
|
||||
* Tests login with destination.
|
||||
*/
|
||||
function testLoginCacheTagsAndDestination() {
|
||||
public function testLoginCacheTagsAndDestination() {
|
||||
$this->drupalGet('user/login');
|
||||
// The user login form says "Enter your <site name> username.", hence it
|
||||
// depends on config:system.site, and its cache tags should be present.
|
||||
$this->assertCacheTag('config:system.site');
|
||||
|
||||
$user = $this->drupalCreateUser(array());
|
||||
$this->drupalGet('user/login', array('query' => array('destination' => 'foo')));
|
||||
$edit = array('name' => $user->getUserName(), 'pass' => $user->pass_raw);
|
||||
$user = $this->drupalCreateUser([]);
|
||||
$this->drupalGet('user/login', ['query' => ['destination' => 'foo']]);
|
||||
$edit = ['name' => $user->getUserName(), 'pass' => $user->pass_raw];
|
||||
$this->drupalPostForm(NULL, $edit, t('Log in'));
|
||||
$this->assertUrl('foo', [], 'Redirected to the correct URL');
|
||||
}
|
||||
|
@ -31,14 +31,14 @@ class UserLoginTest extends WebTestBase {
|
|||
/**
|
||||
* Test the global login flood control.
|
||||
*/
|
||||
function testGlobalLoginFloodControl() {
|
||||
public function testGlobalLoginFloodControl() {
|
||||
$this->config('user.flood')
|
||||
->set('ip_limit', 10)
|
||||
// Set a high per-user limit out so that it is not relevant in the test.
|
||||
->set('user_limit', 4000)
|
||||
->save();
|
||||
|
||||
$user1 = $this->drupalCreateUser(array());
|
||||
$user1 = $this->drupalCreateUser([]);
|
||||
$incorrect_user1 = clone $user1;
|
||||
$incorrect_user1->pass_raw .= 'incorrect';
|
||||
|
||||
|
@ -68,18 +68,18 @@ class UserLoginTest extends WebTestBase {
|
|||
/**
|
||||
* Test the per-user login flood control.
|
||||
*/
|
||||
function testPerUserLoginFloodControl() {
|
||||
public function testPerUserLoginFloodControl() {
|
||||
$this->config('user.flood')
|
||||
// Set a high global limit out so that it is not relevant in the test.
|
||||
->set('ip_limit', 4000)
|
||||
->set('user_limit', 3)
|
||||
->save();
|
||||
|
||||
$user1 = $this->drupalCreateUser(array());
|
||||
$user1 = $this->drupalCreateUser([]);
|
||||
$incorrect_user1 = clone $user1;
|
||||
$incorrect_user1->pass_raw .= 'incorrect';
|
||||
|
||||
$user2 = $this->drupalCreateUser(array());
|
||||
$user2 = $this->drupalCreateUser([]);
|
||||
|
||||
// Try 2 failed logins.
|
||||
for ($i = 0; $i < 2; $i++) {
|
||||
|
@ -108,7 +108,7 @@ class UserLoginTest extends WebTestBase {
|
|||
/**
|
||||
* Test that user password is re-hashed upon login after changing $count_log2.
|
||||
*/
|
||||
function testPasswordRehashOnLogin() {
|
||||
public function testPasswordRehashOnLogin() {
|
||||
// Determine default log2 for phpass hashing algorithm
|
||||
$default_count_log2 = 16;
|
||||
|
||||
|
@ -116,7 +116,7 @@ class UserLoginTest extends WebTestBase {
|
|||
$password_hasher = $this->container->get('password');
|
||||
|
||||
// Create a new user and authenticate.
|
||||
$account = $this->drupalCreateUser(array());
|
||||
$account = $this->drupalCreateUser([]);
|
||||
$password = $account->pass_raw;
|
||||
$this->drupalLogin($account);
|
||||
$this->drupalLogout();
|
||||
|
@ -129,13 +129,13 @@ class UserLoginTest extends WebTestBase {
|
|||
// containing the necessary container builder code and then verify that the
|
||||
// users password gets rehashed during the login.
|
||||
$overridden_count_log2 = 19;
|
||||
\Drupal::service('module_installer')->install(array('user_custom_phpass_params_test'));
|
||||
\Drupal::service('module_installer')->install(['user_custom_phpass_params_test']);
|
||||
$this->resetAll();
|
||||
|
||||
$account->pass_raw = $password;
|
||||
$this->drupalLogin($account);
|
||||
// Load the stored user, which should have a different password hash now.
|
||||
$user_storage->resetCache(array($account->id()));
|
||||
$user_storage->resetCache([$account->id()]);
|
||||
$account = $user_storage->load($account->id());
|
||||
$this->assertIdentical($password_hasher->getCountLog2($account->getPassword()), $overridden_count_log2);
|
||||
$this->assertTrue($password_hasher->check($password, $account->getPassword()));
|
||||
|
@ -154,20 +154,20 @@ class UserLoginTest extends WebTestBase {
|
|||
* .
|
||||
* - Set to NULL to expect a failed login.
|
||||
*/
|
||||
function assertFailedLogin($account, $flood_trigger = NULL) {
|
||||
$edit = array(
|
||||
public function assertFailedLogin($account, $flood_trigger = NULL) {
|
||||
$edit = [
|
||||
'name' => $account->getUsername(),
|
||||
'pass' => $account->pass_raw,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('user/login', $edit, t('Log in'));
|
||||
$this->assertNoFieldByXPath("//input[@name='pass' and @value!='']", NULL, 'Password value attribute is blank.');
|
||||
if (isset($flood_trigger)) {
|
||||
if ($flood_trigger == 'user') {
|
||||
$this->assertRaw(\Drupal::translation()->formatPlural($this->config('user.flood')->get('user_limit'), 'There has been more than one failed login attempt for this account. It is temporarily blocked. Try again later or <a href=":url">request a new password</a>.', 'There have been more than @count failed login attempts for this account. It is temporarily blocked. Try again later or <a href=":url">request a new password</a>.', array(':url' => \Drupal::url('user.pass'))));
|
||||
$this->assertRaw(\Drupal::translation()->formatPlural($this->config('user.flood')->get('user_limit'), 'There has been more than one failed login attempt for this account. It is temporarily blocked. Try again later or <a href=":url">request a new password</a>.', 'There have been more than @count failed login attempts for this account. It is temporarily blocked. Try again later or <a href=":url">request a new password</a>.', [':url' => \Drupal::url('user.pass')]));
|
||||
}
|
||||
else {
|
||||
// No uid, so the limit is IP-based.
|
||||
$this->assertRaw(t('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' => \Drupal::url('user.pass'))));
|
||||
$this->assertRaw(t('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>.', [':url' => \Drupal::url('user.pass')]));
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -61,7 +61,7 @@ class UserPasswordResetTest extends PageCacheTagsTestBase {
|
|||
// that it is definitely over a second ago.
|
||||
$account->login = REQUEST_TIME - mt_rand(10, 100000);
|
||||
db_update('users_field_data')
|
||||
->fields(array('login' => $account->getLastLoginTime()))
|
||||
->fields(['login' => $account->getLastLoginTime()])
|
||||
->condition('uid', $account->id())
|
||||
->execute();
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ class UserPasswordResetTest extends PageCacheTagsTestBase {
|
|||
/**
|
||||
* Tests password reset functionality.
|
||||
*/
|
||||
function testUserPasswordReset() {
|
||||
public function testUserPasswordReset() {
|
||||
// Verify that accessing the password reset form without having the session
|
||||
// variables set results in an access denied message.
|
||||
$this->drupalGet(Url::fromRoute('user.reset.form', ['uid' => $this->account->id()]));
|
||||
|
@ -78,11 +78,11 @@ class UserPasswordResetTest extends PageCacheTagsTestBase {
|
|||
// Try to reset the password for an invalid account.
|
||||
$this->drupalGet('user/password');
|
||||
|
||||
$edit = array('name' => $this->randomMachineName(32));
|
||||
$edit = ['name' => $this->randomMachineName(32)];
|
||||
$this->drupalPostForm(NULL, $edit, t('Submit'));
|
||||
|
||||
$this->assertText(t('@name is not recognized as a username or an email address.', array('@name' => $edit['name'])), 'Validation error message shown when trying to request password for invalid account.');
|
||||
$this->assertEqual(count($this->drupalGetMails(array('id' => 'user_password_reset'))), 0, 'No email was sent when requesting a password for an invalid account.');
|
||||
$this->assertText(t('@name is not recognized as a username or an email address.', ['@name' => $edit['name']]), 'Validation error message shown when trying to request password for invalid account.');
|
||||
$this->assertEqual(count($this->drupalGetMails(['id' => 'user_password_reset'])), 0, 'No email was sent when requesting a password for an invalid account.');
|
||||
|
||||
// Reset the password by username via the password reset page.
|
||||
$edit['name'] = $this->account->getUsername();
|
||||
|
@ -90,7 +90,7 @@ class UserPasswordResetTest extends PageCacheTagsTestBase {
|
|||
|
||||
// Verify that the user was sent an email.
|
||||
$this->assertMail('to', $this->account->getEmail(), 'Password email sent to user.');
|
||||
$subject = t('Replacement login information for @username at @site', array('@username' => $this->account->getUsername(), '@site' => $this->config('system.site')->get('name')));
|
||||
$subject = t('Replacement login information for @username at @site', ['@username' => $this->account->getUsername(), '@site' => $this->config('system.site')->get('name')]);
|
||||
$this->assertMail('subject', $subject, 'Password reset email subject is correct.');
|
||||
|
||||
$resetURL = $this->getResetURL();
|
||||
|
@ -112,19 +112,19 @@ class UserPasswordResetTest extends PageCacheTagsTestBase {
|
|||
// Check successful login.
|
||||
$this->drupalPostForm(NULL, NULL, t('Log in'));
|
||||
$this->assertLink(t('Log out'));
|
||||
$this->assertTitle(t('@name | @site', array('@name' => $this->account->getUsername(), '@site' => $this->config('system.site')->get('name'))), 'Logged in using password reset link.');
|
||||
$this->assertTitle(t('@name | @site', ['@name' => $this->account->getUsername(), '@site' => $this->config('system.site')->get('name')]), 'Logged in using password reset link.');
|
||||
|
||||
// Make sure the ajax request from uploading a user picture does not
|
||||
// invalidate the reset token.
|
||||
$image = current($this->drupalGetTestFiles('image'));
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'files[user_picture_0]' => drupal_realpath($image->uri),
|
||||
);
|
||||
];
|
||||
$this->drupalPostAjaxForm(NULL, $edit, 'user_picture_0_upload_button');
|
||||
|
||||
// Change the forgotten password.
|
||||
$password = user_password();
|
||||
$edit = array('pass[pass1]' => $password, 'pass[pass2]' => $password);
|
||||
$edit = ['pass[pass1]' => $password, 'pass[pass2]' => $password];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$this->assertText(t('The changes have been saved.'), 'Forgotten password changed.');
|
||||
|
||||
|
@ -141,10 +141,10 @@ class UserPasswordResetTest extends PageCacheTagsTestBase {
|
|||
// Request a new password again, this time using the email address.
|
||||
$this->drupalGet('user/password');
|
||||
// Count email messages before to compare with after.
|
||||
$before = count($this->drupalGetMails(array('id' => 'user_password_reset')));
|
||||
$edit = array('name' => $this->account->getEmail());
|
||||
$before = count($this->drupalGetMails(['id' => 'user_password_reset']));
|
||||
$edit = ['name' => $this->account->getEmail()];
|
||||
$this->drupalPostForm(NULL, $edit, t('Submit'));
|
||||
$this->assertTrue( count($this->drupalGetMails(array('id' => 'user_password_reset'))) === $before + 1, 'Email sent when requesting password reset using email address.');
|
||||
$this->assertTrue( count($this->drupalGetMails(['id' => 'user_password_reset'])) === $before + 1, 'Email sent when requesting password reset using email address.');
|
||||
|
||||
// Visit the user edit page without pass-reset-token and make sure it does
|
||||
// not cause an error.
|
||||
|
@ -173,15 +173,15 @@ class UserPasswordResetTest extends PageCacheTagsTestBase {
|
|||
// Verify a blocked user can not request a new password.
|
||||
$this->drupalGet('user/password');
|
||||
// Count email messages before to compare with after.
|
||||
$before = count($this->drupalGetMails(array('id' => 'user_password_reset')));
|
||||
$edit = array('name' => $blocked_account->getUsername());
|
||||
$before = count($this->drupalGetMails(['id' => 'user_password_reset']));
|
||||
$edit = ['name' => $blocked_account->getUsername()];
|
||||
$this->drupalPostForm(NULL, $edit, t('Submit'));
|
||||
$this->assertRaw(t('%name is blocked or has not been activated yet.', array('%name' => $blocked_account->getUsername())), 'Notified user blocked accounts can not request a new password');
|
||||
$this->assertTrue(count($this->drupalGetMails(array('id' => 'user_password_reset'))) === $before, 'No email was sent when requesting password reset for a blocked account');
|
||||
$this->assertRaw(t('%name is blocked or has not been activated yet.', ['%name' => $blocked_account->getUsername()]), 'Notified user blocked accounts can not request a new password');
|
||||
$this->assertTrue(count($this->drupalGetMails(['id' => 'user_password_reset'])) === $before, 'No email was sent when requesting password reset for a blocked account');
|
||||
|
||||
// Verify a password reset link is invalidated when the user's email address changes.
|
||||
$this->drupalGet('user/password');
|
||||
$edit = array('name' => $this->account->getUsername());
|
||||
$edit = ['name' => $this->account->getUsername()];
|
||||
$this->drupalPostForm(NULL, $edit, t('Submit'));
|
||||
$old_email_reset_link = $this->getResetURL();
|
||||
$this->account->setEmail("1" . $this->account->getEmail());
|
||||
|
@ -193,12 +193,12 @@ class UserPasswordResetTest extends PageCacheTagsTestBase {
|
|||
// Verify a password reset link will automatically log a user when /login is
|
||||
// appended.
|
||||
$this->drupalGet('user/password');
|
||||
$edit = array('name' => $this->account->getUsername());
|
||||
$edit = ['name' => $this->account->getUsername()];
|
||||
$this->drupalPostForm(NULL, $edit, t('Submit'));
|
||||
$reset_url = $this->getResetURL();
|
||||
$this->drupalGet($reset_url . '/login');
|
||||
$this->assertLink(t('Log out'));
|
||||
$this->assertTitle(t('@name | @site', array('@name' => $this->account->getUsername(), '@site' => $this->config('system.site')->get('name'))), 'Logged in using password reset link.');
|
||||
$this->assertTitle(t('@name | @site', ['@name' => $this->account->getUsername(), '@site' => $this->config('system.site')->get('name')]), 'Logged in using password reset link.');
|
||||
|
||||
// Ensure blocked and deleted accounts can't access the user.reset.login
|
||||
// route.
|
||||
|
@ -221,7 +221,7 @@ class UserPasswordResetTest extends PageCacheTagsTestBase {
|
|||
// Assume the most recent email.
|
||||
$_emails = $this->drupalGetMails();
|
||||
$email = end($_emails);
|
||||
$urls = array();
|
||||
$urls = [];
|
||||
preg_match('#.+user/reset/.+#', $email['body'], $urls);
|
||||
|
||||
return $urls[0];
|
||||
|
@ -264,7 +264,7 @@ class UserPasswordResetTest extends PageCacheTagsTestBase {
|
|||
|
||||
// Change the password.
|
||||
$password = user_password();
|
||||
$edit = array('pass[pass1]' => $password, 'pass[pass2]' => $password);
|
||||
$edit = ['pass[pass1]' => $password, 'pass[pass2]' => $password];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$this->assertText(t('The changes have been saved.'), 'Password changed.');
|
||||
|
||||
|
@ -282,15 +282,15 @@ class UserPasswordResetTest extends PageCacheTagsTestBase {
|
|||
*/
|
||||
public function testUserResetPasswordTextboxFilled() {
|
||||
$this->drupalGet('user/login');
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'name' => $this->randomMachineName(),
|
||||
'pass' => $this->randomMachineName(),
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('user/login', $edit, t('Log in'));
|
||||
$this->assertRaw(t('Unrecognized username or password. <a href=":password">Forgot your password?</a>',
|
||||
array(':password' => \Drupal::url('user.pass', [], array('query' => array('name' => $edit['name']))))));
|
||||
[':password' => \Drupal::url('user.pass', [], ['query' => ['name' => $edit['name']]])]));
|
||||
unset($edit['pass']);
|
||||
$this->drupalGet('user/password', array('query' => array('name' => $edit['name'])));
|
||||
$this->drupalGet('user/password', ['query' => ['name' => $edit['name']]]);
|
||||
$this->assertFieldByName('name', $edit['name'], 'User name found.');
|
||||
// Ensure the name field value is not cached.
|
||||
$this->drupalGet('user/password');
|
||||
|
@ -300,10 +300,10 @@ class UserPasswordResetTest extends PageCacheTagsTestBase {
|
|||
/**
|
||||
* Make sure that users cannot forge password reset URLs of other users.
|
||||
*/
|
||||
function testResetImpersonation() {
|
||||
public function testResetImpersonation() {
|
||||
// Create two identical user accounts except for the user name. They must
|
||||
// have the same empty password, so we can't use $this->drupalCreateUser().
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['name'] = $this->randomMachineName();
|
||||
$edit['mail'] = $edit['name'] . '@example.com';
|
||||
$edit['status'] = 1;
|
||||
|
@ -333,7 +333,7 @@ class UserPasswordResetTest extends PageCacheTagsTestBase {
|
|||
$this->drupalGet($attack_reset_url);
|
||||
$this->drupalPostForm(NULL, NULL, t('Log in'));
|
||||
$this->assertNoText($user2->getUsername(), 'The invalid password reset page does not show the user name.');
|
||||
$this->assertUrl('user/password', array(), 'The user is redirected to the password reset request page.');
|
||||
$this->assertUrl('user/password', [], 'The user is redirected to the password reset request page.');
|
||||
$this->assertText('You have tried to use a one-time login link that has either been used or is no longer valid. Please request a new one using the form below.');
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ class UserPermissionsTest extends WebTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->adminUser = $this->drupalCreateUser(array('administer permissions', 'access user profiles', 'administer site configuration', 'administer modules', 'administer account settings'));
|
||||
$this->adminUser = $this->drupalCreateUser(['administer permissions', 'access user profiles', 'administer site configuration', 'administer modules', 'administer account settings']);
|
||||
|
||||
// Find the new role ID.
|
||||
$all_rids = $this->adminUser->getRoles();
|
||||
|
@ -42,7 +42,7 @@ class UserPermissionsTest extends WebTestBase {
|
|||
/**
|
||||
* Test changing user permissions through the permissions page.
|
||||
*/
|
||||
function testUserPermissionChanges() {
|
||||
public function testUserPermissionChanges() {
|
||||
$permissions_hash_generator = $this->container->get('user_permissions_hash_generator');
|
||||
|
||||
$storage = $this->container->get('entity.manager')->getStorage('user_role');
|
||||
|
@ -59,7 +59,7 @@ class UserPermissionsTest extends WebTestBase {
|
|||
|
||||
// Add a permission.
|
||||
$this->assertFalse($account->hasPermission('administer users'), 'User does not have "administer users" permission.');
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit[$rid . '[administer users]'] = TRUE;
|
||||
$this->drupalPostForm('admin/people/permissions', $edit, t('Save permissions'));
|
||||
$this->assertText(t('The changes have been saved.'), 'Successful save message displayed.');
|
||||
|
@ -72,7 +72,7 @@ class UserPermissionsTest extends WebTestBase {
|
|||
|
||||
// Remove a permission.
|
||||
$this->assertTrue($account->hasPermission('access user profiles'), 'User has "access user profiles" permission.');
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit[$rid . '[access user profiles]'] = FALSE;
|
||||
$this->drupalPostForm('admin/people/permissions', $edit, t('Save permissions'));
|
||||
$this->assertText(t('The changes have been saved.'), 'Successful save message displayed.');
|
||||
|
@ -92,7 +92,7 @@ class UserPermissionsTest extends WebTestBase {
|
|||
/**
|
||||
* Test assigning of permissions for the administrator role.
|
||||
*/
|
||||
function testAdministratorRole() {
|
||||
public function testAdministratorRole() {
|
||||
$this->drupalLogin($this->adminUser);
|
||||
$this->drupalGet('admin/config/people/accounts');
|
||||
|
||||
|
@ -102,7 +102,7 @@ class UserPermissionsTest extends WebTestBase {
|
|||
$this->assertFalse(Role::load($this->rid)->isAdmin());
|
||||
|
||||
// Set the user's role to be the administrator role.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['user_admin_role'] = $this->rid;
|
||||
$this->drupalPostForm('admin/config/people/accounts', $edit, t('Save configuration'));
|
||||
|
||||
|
@ -111,12 +111,12 @@ class UserPermissionsTest extends WebTestBase {
|
|||
|
||||
// Enable aggregator module and ensure the 'administer news feeds'
|
||||
// permission is assigned by default.
|
||||
\Drupal::service('module_installer')->install(array('aggregator'));
|
||||
\Drupal::service('module_installer')->install(['aggregator']);
|
||||
|
||||
$this->assertTrue($this->adminUser->hasPermission('administer news feeds'), 'The permission was automatically assigned to the administrator role');
|
||||
|
||||
// Ensure that selecting '- None -' removes the admin role.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['user_admin_role'] = '';
|
||||
$this->drupalPostForm('admin/config/people/accounts', $edit, t('Save configuration'));
|
||||
|
||||
|
@ -135,7 +135,7 @@ class UserPermissionsTest extends WebTestBase {
|
|||
/**
|
||||
* Verify proper permission changes by user_role_change_permissions().
|
||||
*/
|
||||
function testUserRoleChangePermissions() {
|
||||
public function testUserRoleChangePermissions() {
|
||||
$permissions_hash_generator = $this->container->get('user_permissions_hash_generator');
|
||||
|
||||
$rid = $this->rid;
|
||||
|
@ -148,10 +148,10 @@ class UserPermissionsTest extends WebTestBase {
|
|||
$this->assertTrue($account->hasPermission('administer site configuration'), 'User has "administer site configuration" permission.');
|
||||
|
||||
// Change permissions.
|
||||
$permissions = array(
|
||||
$permissions = [
|
||||
'administer users' => 1,
|
||||
'access user profiles' => 0,
|
||||
);
|
||||
];
|
||||
user_role_change_permissions($rid, $permissions);
|
||||
|
||||
// Verify proper permission changes.
|
||||
|
|
|
@ -33,18 +33,18 @@ class UserPictureTest extends WebTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->webUser = $this->drupalCreateUser(array(
|
||||
$this->webUser = $this->drupalCreateUser([
|
||||
'access content',
|
||||
'access comments',
|
||||
'post comments',
|
||||
'skip comment approval',
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests creation, display, and deletion of user pictures.
|
||||
*/
|
||||
function testCreateDeletePicture() {
|
||||
public function testCreateDeletePicture() {
|
||||
$this->drupalLogin($this->webUser);
|
||||
|
||||
// Save a new picture.
|
||||
|
@ -56,17 +56,17 @@ class UserPictureTest extends WebTestBase {
|
|||
$this->assertRaw(file_uri_target($file->getFileUri()), 'User picture found on user account page.');
|
||||
|
||||
// Delete the picture.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$this->drupalPostForm('user/' . $this->webUser->id() . '/edit', $edit, t('Remove'));
|
||||
$this->drupalPostForm(NULL, array(), t('Save'));
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
|
||||
// Call file_cron() to clean up the file. Make sure the timestamp
|
||||
// of the file is older than the system.file.temporary_maximum_age
|
||||
// configuration value.
|
||||
db_update('file_managed')
|
||||
->fields(array(
|
||||
->fields([
|
||||
'changed' => REQUEST_TIME - ($this->config('system.file')->get('temporary_maximum_age') + 1),
|
||||
))
|
||||
])
|
||||
->condition('fid', $file->id())
|
||||
->execute();
|
||||
\Drupal::service('cron')->run();
|
||||
|
@ -81,14 +81,14 @@ class UserPictureTest extends WebTestBase {
|
|||
/**
|
||||
* Tests embedded users on node pages.
|
||||
*/
|
||||
function testPictureOnNodeComment() {
|
||||
public function testPictureOnNodeComment() {
|
||||
$this->drupalLogin($this->webUser);
|
||||
|
||||
// Save a new picture.
|
||||
$image = current($this->drupalGetTestFiles('image'));
|
||||
$file = $this->saveUserPicture($image);
|
||||
|
||||
$node = $this->drupalCreateNode(array('type' => 'article'));
|
||||
$node = $this->drupalCreateNode(['type' => 'article']);
|
||||
|
||||
// Enable user pictures on nodes.
|
||||
$this->config('system.theme.global')->set('features.node_user_picture', TRUE)->save();
|
||||
|
@ -109,9 +109,9 @@ class UserPictureTest extends WebTestBase {
|
|||
->set('features.comment_user_picture', TRUE)
|
||||
->save();
|
||||
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'comment_body[0][value]' => $this->randomString(),
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('comment/reply/node/' . $node->id() . '/comment', $edit, t('Save'));
|
||||
$elements = $this->cssSelect('.comment__meta .field--name-user-picture img[alt="' . $alt_text . '"][src="' . $image_url . '"]');
|
||||
$this->assertEqual(count($elements), 1, 'User picture with alt text found on the comment.');
|
||||
|
@ -129,13 +129,13 @@ class UserPictureTest extends WebTestBase {
|
|||
/**
|
||||
* Edits the user picture for the test user.
|
||||
*/
|
||||
function saveUserPicture($image) {
|
||||
$edit = array('files[user_picture_0]' => drupal_realpath($image->uri));
|
||||
public function saveUserPicture($image) {
|
||||
$edit = ['files[user_picture_0]' => drupal_realpath($image->uri)];
|
||||
$this->drupalPostForm('user/' . $this->webUser->id() . '/edit', $edit, t('Save'));
|
||||
|
||||
// Load actual user data from database.
|
||||
$user_storage = $this->container->get('entity.manager')->getStorage('user');
|
||||
$user_storage->resetCache(array($this->webUser->id()));
|
||||
$user_storage->resetCache([$this->webUser->id()]);
|
||||
$account = $user_storage->load($this->webUser->id());
|
||||
return File::load($account->user_picture->target_id);
|
||||
}
|
||||
|
|
|
@ -21,9 +21,9 @@ class UserRegistrationTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('field_test');
|
||||
public static $modules = ['field_test'];
|
||||
|
||||
function testRegistrationWithEmailVerification() {
|
||||
public function testRegistrationWithEmailVerification() {
|
||||
$config = $this->config('user.settings');
|
||||
// Require email verification.
|
||||
$config->set('verify_mail', TRUE)->save();
|
||||
|
@ -35,7 +35,7 @@ class UserRegistrationTest extends WebTestBase {
|
|||
|
||||
// Allow registration by site visitors without administrator approval.
|
||||
$config->set('register', USER_REGISTER_VISITORS)->save();
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['name'] = $name = $this->randomMachineName();
|
||||
$edit['mail'] = $mail = $edit['name'] . '@example.com';
|
||||
$this->drupalPostForm('user/register', $edit, t('Create new account'));
|
||||
|
@ -52,7 +52,7 @@ class UserRegistrationTest extends WebTestBase {
|
|||
|
||||
// Allow registration by site visitors, but require administrator approval.
|
||||
$config->set('register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)->save();
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['name'] = $name = $this->randomMachineName();
|
||||
$edit['mail'] = $mail = $edit['name'] . '@example.com';
|
||||
$this->drupalPostForm('user/register', $edit, t('Create new account'));
|
||||
|
@ -62,7 +62,7 @@ class UserRegistrationTest extends WebTestBase {
|
|||
$this->assertFalse($new_user->isActive(), 'New account is blocked until approved by an administrator.');
|
||||
}
|
||||
|
||||
function testRegistrationWithoutEmailVerification() {
|
||||
public function testRegistrationWithoutEmailVerification() {
|
||||
$config = $this->config('user.settings');
|
||||
// Don't require email verification and allow registration by site visitors
|
||||
// without administrator approval.
|
||||
|
@ -71,7 +71,7 @@ class UserRegistrationTest extends WebTestBase {
|
|||
->set('register', USER_REGISTER_VISITORS)
|
||||
->save();
|
||||
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['name'] = $name = $this->randomMachineName();
|
||||
$edit['mail'] = $mail = $edit['name'] . '@example.com';
|
||||
|
||||
|
@ -95,7 +95,7 @@ class UserRegistrationTest extends WebTestBase {
|
|||
|
||||
// Allow registration by site visitors, but require administrator approval.
|
||||
$config->set('register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)->save();
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['name'] = $name = $this->randomMachineName();
|
||||
$edit['mail'] = $mail = $edit['name'] . '@example.com';
|
||||
$edit['pass[pass1]'] = $pass = $this->randomMachineName();
|
||||
|
@ -104,22 +104,22 @@ class UserRegistrationTest extends WebTestBase {
|
|||
$this->assertText(t('Thank you for applying for an account. Your account is currently pending approval by the site administrator.'), 'Users are notified of pending approval');
|
||||
|
||||
// Try to log in before administrator approval.
|
||||
$auth = array(
|
||||
$auth = [
|
||||
'name' => $name,
|
||||
'pass' => $pass,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('user/login', $auth, t('Log in'));
|
||||
$this->assertText(t('The username @name has not been activated or is blocked.', array('@name' => $name)), 'User cannot log in yet.');
|
||||
$this->assertText(t('The username @name has not been activated or is blocked.', ['@name' => $name]), 'User cannot log in yet.');
|
||||
|
||||
// Activate the new account.
|
||||
$accounts = $this->container->get('entity_type.manager')->getStorage('user')
|
||||
->loadByProperties(['name' => $name, 'mail' => $mail]);
|
||||
$new_user = reset($accounts);
|
||||
$admin_user = $this->drupalCreateUser(array('administer users'));
|
||||
$admin_user = $this->drupalCreateUser(['administer users']);
|
||||
$this->drupalLogin($admin_user);
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'status' => 1,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('user/' . $new_user->id() . '/edit', $edit, t('Save'));
|
||||
$this->drupalLogout();
|
||||
|
||||
|
@ -128,7 +128,7 @@ class UserRegistrationTest extends WebTestBase {
|
|||
$this->assertText(t('Member for'), 'User can log in after administrator approval.');
|
||||
}
|
||||
|
||||
function testRegistrationEmailDuplicates() {
|
||||
public function testRegistrationEmailDuplicates() {
|
||||
// Don't require email verification and allow registration by site visitors
|
||||
// without administrator approval.
|
||||
$this->config('user.settings')
|
||||
|
@ -139,19 +139,19 @@ class UserRegistrationTest extends WebTestBase {
|
|||
// Set up a user to check for duplicates.
|
||||
$duplicate_user = $this->drupalCreateUser();
|
||||
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['name'] = $this->randomMachineName();
|
||||
$edit['mail'] = $duplicate_user->getEmail();
|
||||
|
||||
// Attempt to create a new account using an existing email address.
|
||||
$this->drupalPostForm('user/register', $edit, t('Create new account'));
|
||||
$this->assertText(t('The email address @email is already taken.', array('@email' => $duplicate_user->getEmail())), 'Supplying an exact duplicate email address displays an error message');
|
||||
$this->assertText(t('The email address @email is already taken.', ['@email' => $duplicate_user->getEmail()]), 'Supplying an exact duplicate email address displays an error message');
|
||||
|
||||
// Attempt to bypass duplicate email registration validation by adding spaces.
|
||||
$edit['mail'] = ' ' . $duplicate_user->getEmail() . ' ';
|
||||
|
||||
$this->drupalPostForm('user/register', $edit, t('Create new account'));
|
||||
$this->assertText(t('The email address @email is already taken.', array('@email' => $duplicate_user->getEmail())), 'Supplying a duplicate email address with added whitespace displays an error message');
|
||||
$this->assertText(t('The email address @email is already taken.', ['@email' => $duplicate_user->getEmail()]), 'Supplying a duplicate email address with added whitespace displays an error message');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -223,7 +223,7 @@ class UserRegistrationTest extends WebTestBase {
|
|||
$this->assertTrue($user_storage->loadByProperties(['name' => $edit['name']]));
|
||||
}
|
||||
|
||||
function testRegistrationDefaultValues() {
|
||||
public function testRegistrationDefaultValues() {
|
||||
// Don't require email verification and allow registration by site visitors
|
||||
// without administrator approval.
|
||||
$config_user_settings = $this->config('user.settings')
|
||||
|
@ -237,15 +237,11 @@ class UserRegistrationTest extends WebTestBase {
|
|||
->set('timezone.default', 'Europe/Brussels')
|
||||
->save();
|
||||
|
||||
// Check that the account information options are not displayed
|
||||
// as a details element if there is not more than one details in the form.
|
||||
$this->drupalGet('user/register');
|
||||
$this->assertNoRaw('<details id="edit-account"><summary>Account information</summary>');
|
||||
|
||||
// Check the presence of expected cache tags.
|
||||
$this->drupalGet('user/register');
|
||||
$this->assertCacheTag('config:user.settings');
|
||||
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['name'] = $name = $this->randomMachineName();
|
||||
$edit['mail'] = $mail = $edit['name'] . '@example.com';
|
||||
$edit['pass[pass1]'] = $new_pass = $this->randomMachineName();
|
||||
|
@ -287,14 +283,14 @@ class UserRegistrationTest extends WebTestBase {
|
|||
/**
|
||||
* Tests Field API fields on user registration forms.
|
||||
*/
|
||||
function testRegistrationWithUserFields() {
|
||||
public function testRegistrationWithUserFields() {
|
||||
// Create a field on 'user' entity type.
|
||||
$field_storage = FieldStorageConfig::create(array(
|
||||
$field_storage = FieldStorageConfig::create([
|
||||
'field_name' => 'test_user_field',
|
||||
'entity_type' => 'user',
|
||||
'type' => 'test_field',
|
||||
'cardinality' => 1,
|
||||
));
|
||||
]);
|
||||
$field_storage->save();
|
||||
$field = FieldConfig::create([
|
||||
'field_storage' => $field_storage,
|
||||
|
@ -304,7 +300,7 @@ class UserRegistrationTest extends WebTestBase {
|
|||
]);
|
||||
$field->save();
|
||||
entity_get_form_display('user', 'user', 'default')
|
||||
->setComponent('test_user_field', array('type' => 'test_field_widget'))
|
||||
->setComponent('test_user_field', ['type' => 'test_field_widget'])
|
||||
->save();
|
||||
entity_get_form_display('user', 'user', 'register')
|
||||
->save();
|
||||
|
@ -317,7 +313,7 @@ class UserRegistrationTest extends WebTestBase {
|
|||
|
||||
// Have the field appear on the registration form.
|
||||
entity_get_form_display('user', 'user', 'register')
|
||||
->setComponent('test_user_field', array('type' => 'test_field_widget'))
|
||||
->setComponent('test_user_field', ['type' => 'test_field_widget'])
|
||||
->save();
|
||||
|
||||
$this->drupalGet('user/register');
|
||||
|
@ -325,19 +321,19 @@ class UserRegistrationTest extends WebTestBase {
|
|||
$this->assertRegistrationFormCacheTagsWithUserFields();
|
||||
|
||||
// Check that validation errors are correctly reported.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['name'] = $name = $this->randomMachineName();
|
||||
$edit['mail'] = $mail = $edit['name'] . '@example.com';
|
||||
// Missing input in required field.
|
||||
$edit['test_user_field[0][value]'] = '';
|
||||
$this->drupalPostForm(NULL, $edit, t('Create new account'));
|
||||
$this->assertRegistrationFormCacheTagsWithUserFields();
|
||||
$this->assertRaw(t('@name field is required.', array('@name' => $field->label())), 'Field validation error was correctly reported.');
|
||||
$this->assertRaw(t('@name field is required.', ['@name' => $field->label()]), 'Field validation error was correctly reported.');
|
||||
// Invalid input.
|
||||
$edit['test_user_field[0][value]'] = '-1';
|
||||
$this->drupalPostForm(NULL, $edit, t('Create new account'));
|
||||
$this->assertRegistrationFormCacheTagsWithUserFields();
|
||||
$this->assertRaw(t('%name does not accept the value -1.', array('%name' => $field->label())), 'Field validation error was correctly reported.');
|
||||
$this->assertRaw(t('%name does not accept the value -1.', ['%name' => $field->label()]), 'Field validation error was correctly reported.');
|
||||
|
||||
// Submit with valid data.
|
||||
$value = rand(1, 255);
|
||||
|
@ -352,12 +348,12 @@ class UserRegistrationTest extends WebTestBase {
|
|||
// Check that the 'add more' button works.
|
||||
$field_storage->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
|
||||
$field_storage->save();
|
||||
foreach (array('js', 'nojs') as $js) {
|
||||
foreach (['js', 'nojs'] as $js) {
|
||||
$this->drupalGet('user/register');
|
||||
$this->assertRegistrationFormCacheTagsWithUserFields();
|
||||
// Add two inputs.
|
||||
$value = rand(1, 255);
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['test_user_field[0][value]'] = $value;
|
||||
if ($js == 'js') {
|
||||
$this->drupalPostAjaxForm(NULL, $edit, 'test_user_field_add_more');
|
||||
|
@ -375,11 +371,11 @@ class UserRegistrationTest extends WebTestBase {
|
|||
$this->drupalPostForm(NULL, $edit, t('Create new account'));
|
||||
// Check user fields.
|
||||
$accounts = $this->container->get('entity_type.manager')->getStorage('user')
|
||||
->loadByProperties(array('name' => $name, 'mail' => $mail));
|
||||
->loadByProperties(['name' => $name, 'mail' => $mail]);
|
||||
$new_user = reset($accounts);
|
||||
$this->assertEqual($new_user->test_user_field[0]->value, $value, format_string('@js : The field value was correctly saved.', array('@js' => $js)));
|
||||
$this->assertEqual($new_user->test_user_field[1]->value, $value + 1, format_string('@js : The field value was correctly saved.', array('@js' => $js)));
|
||||
$this->assertEqual($new_user->test_user_field[2]->value, $value + 2, format_string('@js : The field value was correctly saved.', array('@js' => $js)));
|
||||
$this->assertEqual($new_user->test_user_field[0]->value, $value, format_string('@js : The field value was correctly saved.', ['@js' => $js]));
|
||||
$this->assertEqual($new_user->test_user_field[1]->value, $value + 1, format_string('@js : The field value was correctly saved.', ['@js' => $js]));
|
||||
$this->assertEqual($new_user->test_user_field[2]->value, $value + 2, format_string('@js : The field value was correctly saved.', ['@js' => $js]));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,31 +32,31 @@ class UserRoleAdminTest extends WebTestBase {
|
|||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->adminUser = $this->drupalCreateUser(array('administer permissions', 'administer users'));
|
||||
$this->adminUser = $this->drupalCreateUser(['administer permissions', 'administer users']);
|
||||
$this->drupalPlaceBlock('local_tasks_block');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test adding, renaming and deleting roles.
|
||||
*/
|
||||
function testRoleAdministration() {
|
||||
public function testRoleAdministration() {
|
||||
$this->drupalLogin($this->adminUser);
|
||||
$default_langcode = \Drupal::languageManager()->getDefaultLanguage()->getId();
|
||||
// Test presence of tab.
|
||||
$this->drupalGet('admin/people/permissions');
|
||||
$tabs = $this->xpath('//ul[@class=:classes and //a[contains(., :text)]]', array(
|
||||
$tabs = $this->xpath('//ul[@class=:classes and //a[contains(., :text)]]', [
|
||||
':classes' => 'tabs primary',
|
||||
':text' => t('Roles'),
|
||||
));
|
||||
]);
|
||||
$this->assertEqual(count($tabs), 1, 'Found roles tab');
|
||||
|
||||
// Test adding a role. (In doing so, we use a role name that happens to
|
||||
// correspond to an integer, to test that the role administration pages
|
||||
// correctly distinguish between role names and IDs.)
|
||||
$role_name = '123';
|
||||
$edit = array('label' => $role_name, 'id' => $role_name);
|
||||
$edit = ['label' => $role_name, 'id' => $role_name];
|
||||
$this->drupalPostForm('admin/people/roles/add', $edit, t('Save'));
|
||||
$this->assertRaw(t('Role %label has been added.', array('%label' => 123)));
|
||||
$this->assertRaw(t('Role %label has been added.', ['%label' => 123]));
|
||||
$role = Role::load($role_name);
|
||||
$this->assertTrue(is_object($role), 'The role was successfully retrieved from the database.');
|
||||
|
||||
|
@ -69,20 +69,20 @@ class UserRoleAdminTest extends WebTestBase {
|
|||
|
||||
// Test renaming a role.
|
||||
$role_name = '456';
|
||||
$edit = array('label' => $role_name);
|
||||
$edit = ['label' => $role_name];
|
||||
$this->drupalPostForm("admin/people/roles/manage/{$role->id()}", $edit, t('Save'));
|
||||
$this->assertRaw(t('Role %label has been updated.', array('%label' => $role_name)));
|
||||
\Drupal::entityManager()->getStorage('user_role')->resetCache(array($role->id()));
|
||||
$this->assertRaw(t('Role %label has been updated.', ['%label' => $role_name]));
|
||||
\Drupal::entityManager()->getStorage('user_role')->resetCache([$role->id()]);
|
||||
$new_role = Role::load($role->id());
|
||||
$this->assertEqual($new_role->label(), $role_name, 'The role name has been successfully changed.');
|
||||
|
||||
// Test deleting a role.
|
||||
$this->drupalGet("admin/people/roles/manage/{$role->id()}");
|
||||
$this->clickLink(t('Delete'));
|
||||
$this->drupalPostForm(NULL, array(), t('Delete'));
|
||||
$this->assertRaw(t('The role %label has been deleted.', array('%label' => $role_name)));
|
||||
$this->drupalPostForm(NULL, [], t('Delete'));
|
||||
$this->assertRaw(t('The role %label has been deleted.', ['%label' => $role_name]));
|
||||
$this->assertNoLinkByHref("admin/people/roles/manage/{$role->id()}", 'Role edit link removed.');
|
||||
\Drupal::entityManager()->getStorage('user_role')->resetCache(array($role->id()));
|
||||
\Drupal::entityManager()->getStorage('user_role')->resetCache([$role->id()]);
|
||||
$this->assertFalse(Role::load($role->id()), 'A deleted role can no longer be loaded.');
|
||||
|
||||
// Make sure that the system-defined roles can be edited via the user
|
||||
|
@ -98,15 +98,15 @@ class UserRoleAdminTest extends WebTestBase {
|
|||
/**
|
||||
* Test user role weight change operation and ordering.
|
||||
*/
|
||||
function testRoleWeightOrdering() {
|
||||
public function testRoleWeightOrdering() {
|
||||
$this->drupalLogin($this->adminUser);
|
||||
$roles = user_roles();
|
||||
$weight = count($roles);
|
||||
$new_role_weights = array();
|
||||
$saved_rids = array();
|
||||
$new_role_weights = [];
|
||||
$saved_rids = [];
|
||||
|
||||
// Change the role weights to make the roles in reverse order.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
foreach ($roles as $role) {
|
||||
$edit['entities[' . $role->id() . '][weight]'] = $weight;
|
||||
$new_role_weights[$role->id()] = $weight;
|
||||
|
@ -119,7 +119,7 @@ class UserRoleAdminTest extends WebTestBase {
|
|||
// Load up the user roles with the new weights.
|
||||
drupal_static_reset('user_roles');
|
||||
$roles = user_roles();
|
||||
$rids = array();
|
||||
$rids = [];
|
||||
// Test that the role weights have been correctly saved.
|
||||
foreach ($roles as $role) {
|
||||
$this->assertEqual($role->getWeight(), $new_role_weights[$role->id()]);
|
||||
|
|
|
@ -17,19 +17,26 @@ class UserTimeZoneTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'system_test');
|
||||
public static $modules = ['node', 'system_test'];
|
||||
|
||||
/**
|
||||
* Tests the display of dates and time when user-configurable time zones are set.
|
||||
*/
|
||||
function testUserTimeZone() {
|
||||
public function testUserTimeZone() {
|
||||
// Setup date/time settings for Los Angeles time.
|
||||
$this->config('system.date')
|
||||
->set('timezone.user.configurable', 1)
|
||||
->set('timezone.default', 'America/Los_Angeles')
|
||||
->save();
|
||||
|
||||
// Load the 'medium' date format, which is the default for node creation
|
||||
// time, and override it. Since we are testing time zones with Daylight
|
||||
// Saving Time, and need to future proof against changes to the zoneinfo
|
||||
// database, we choose the 'I' format placeholder instead of a
|
||||
// human-readable zone name. With 'I', a 1 means the date is in DST, and 0
|
||||
// if not.
|
||||
DateFormat::load('medium')
|
||||
->setPattern('Y-m-d H:i T')
|
||||
->setPattern('Y-m-d H:i I')
|
||||
->save();
|
||||
|
||||
// Create a user account and login.
|
||||
|
@ -42,21 +49,21 @@ class UserTimeZoneTest extends WebTestBase {
|
|||
$date2 = '2007-03-11 01:00:00 -0800';
|
||||
// One date in PDT (summer time):
|
||||
$date3 = '2007-03-20 21:00:00 -0700';
|
||||
$this->drupalCreateContentType(array('type' => 'article'));
|
||||
$node1 = $this->drupalCreateNode(array('created' => strtotime($date1), 'type' => 'article'));
|
||||
$node2 = $this->drupalCreateNode(array('created' => strtotime($date2), 'type' => 'article'));
|
||||
$node3 = $this->drupalCreateNode(array('created' => strtotime($date3), 'type' => 'article'));
|
||||
$this->drupalCreateContentType(['type' => 'article']);
|
||||
$node1 = $this->drupalCreateNode(['created' => strtotime($date1), 'type' => 'article']);
|
||||
$node2 = $this->drupalCreateNode(['created' => strtotime($date2), 'type' => 'article']);
|
||||
$node3 = $this->drupalCreateNode(['created' => strtotime($date3), 'type' => 'article']);
|
||||
|
||||
// Confirm date format and time zone.
|
||||
$this->drupalGet('node/' . $node1->id());
|
||||
$this->assertText('2007-03-09 21:00 PST', 'Date should be PST.');
|
||||
$this->assertText('2007-03-09 21:00 0', 'Date should be PST.');
|
||||
$this->drupalGet('node/' . $node2->id());
|
||||
$this->assertText('2007-03-11 01:00 PST', 'Date should be PST.');
|
||||
$this->assertText('2007-03-11 01:00 0', 'Date should be PST.');
|
||||
$this->drupalGet('node/' . $node3->id());
|
||||
$this->assertText('2007-03-20 21:00 PDT', 'Date should be PDT.');
|
||||
$this->assertText('2007-03-20 21:00 1', 'Date should be PDT.');
|
||||
|
||||
// Change user time zone to Santiago time.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['mail'] = $web_user->getEmail();
|
||||
$edit['timezone'] = 'America/Santiago';
|
||||
$this->drupalPostForm("user/" . $web_user->id() . "/edit", $edit, t('Save'));
|
||||
|
@ -64,25 +71,25 @@ class UserTimeZoneTest extends WebTestBase {
|
|||
|
||||
// Confirm date format and time zone.
|
||||
$this->drupalGet('node/' . $node1->id());
|
||||
$this->assertText('2007-03-10 02:00 CLST', 'Date should be Chile summer time; five hours ahead of PST.');
|
||||
$this->assertText('2007-03-10 02:00 1', 'Date should be Chile summer time; five hours ahead of PST.');
|
||||
$this->drupalGet('node/' . $node2->id());
|
||||
$this->assertText('2007-03-11 05:00 CLT', 'Date should be Chile time; four hours ahead of PST');
|
||||
$this->assertText('2007-03-11 05:00 0', 'Date should be Chile time; four hours ahead of PST');
|
||||
$this->drupalGet('node/' . $node3->id());
|
||||
$this->assertText('2007-03-21 00:00 CLT', 'Date should be Chile time; three hours ahead of PDT.');
|
||||
$this->assertText('2007-03-21 00:00 0', 'Date should be Chile time; three hours ahead of PDT.');
|
||||
|
||||
// Ensure that anonymous users also use the default timezone.
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet('node/' . $node1->id());
|
||||
$this->assertText('2007-03-09 21:00 PST', 'Date should be PST.');
|
||||
$this->assertText('2007-03-09 21:00 0', 'Date should be PST.');
|
||||
$this->drupalGet('node/' . $node2->id());
|
||||
$this->assertText('2007-03-11 01:00 PST', 'Date should be PST.');
|
||||
$this->assertText('2007-03-11 01:00 0', 'Date should be PST.');
|
||||
$this->drupalGet('node/' . $node3->id());
|
||||
$this->assertText('2007-03-20 21:00 PDT', 'Date should be PDT.');
|
||||
$this->assertText('2007-03-20 21:00 1', 'Date should be PDT.');
|
||||
|
||||
// Format a date without accessing the current user at all and
|
||||
// ensure that it uses the default timezone.
|
||||
$this->drupalGet('/system-test/date');
|
||||
$this->assertText('2016-01-13 08:29 PST', 'Date should be PST.');
|
||||
$this->assertText('2016-01-13 08:29 0', 'Date should be PST.');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ class UserTranslationUITest extends ContentTranslationUITestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('language', 'content_translation', 'user', 'views');
|
||||
public static $modules = ['language', 'content_translation', 'user', 'views'];
|
||||
|
||||
protected function setUp() {
|
||||
$this->entityTypeId = 'user';
|
||||
|
@ -38,7 +38,7 @@ class UserTranslationUITest extends ContentTranslationUITestBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getTranslatorPermissions() {
|
||||
return array_merge(parent::getTranslatorPermissions(), array('administer users'));
|
||||
return array_merge(parent::getTranslatorPermissions(), ['administer users']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -46,7 +46,7 @@ class UserTranslationUITest extends ContentTranslationUITestBase {
|
|||
*/
|
||||
protected function getNewEntityValues($langcode) {
|
||||
// User name is not translatable hence we use a fixed value.
|
||||
return array('name' => $this->name) + parent::getNewEntityValues($langcode);
|
||||
return ['name' => $this->name] + parent::getNewEntityValues($langcode);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -62,14 +62,14 @@ class UserTranslationUITest extends ContentTranslationUITestBase {
|
|||
foreach ($this->langcodes as $langcode) {
|
||||
// We only want to test the title for non-english translations.
|
||||
if ($langcode != 'en') {
|
||||
$options = array('language' => $languages[$langcode]);
|
||||
$options = ['language' => $languages[$langcode]];
|
||||
$url = $entity->urlInfo('edit-form', $options);
|
||||
$this->drupalGet($url);
|
||||
|
||||
$title = t('@title [%language translation]', array(
|
||||
$title = t('@title [%language translation]', [
|
||||
'@title' => $entity->getTranslation($langcode)->label(),
|
||||
'%language' => $languages[$langcode]->getName(),
|
||||
));
|
||||
]);
|
||||
$this->assertRaw($title);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,12 +19,12 @@ class AccessPermissionTest extends AccessTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_access_perm');
|
||||
public static $testViews = ['test_access_perm'];
|
||||
|
||||
/**
|
||||
* Tests perm access plugin.
|
||||
*/
|
||||
function testAccessPerm() {
|
||||
public function testAccessPerm() {
|
||||
$view = Views::getView('test_access_perm');
|
||||
$view->setDisplay();
|
||||
|
||||
|
|
|
@ -20,18 +20,18 @@ class AccessRoleTest extends AccessTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_access_role');
|
||||
public static $testViews = ['test_access_role'];
|
||||
|
||||
/**
|
||||
* Tests role access plugin.
|
||||
*/
|
||||
function testAccessRole() {
|
||||
public function testAccessRole() {
|
||||
/** @var \Drupal\views\ViewEntityInterface $view */
|
||||
$view = \Drupal::entityManager()->getStorage('view')->load('test_access_role');
|
||||
$display = &$view->getDisplay('default');
|
||||
$display['display_options']['access']['options']['role'] = array(
|
||||
$display['display_options']['access']['options']['role'] = [
|
||||
$this->normalRole => $this->normalRole,
|
||||
);
|
||||
];
|
||||
$view->save();
|
||||
$this->container->get('router.builder')->rebuildIfNeeded();
|
||||
$expected = [
|
||||
|
@ -63,10 +63,10 @@ class AccessRoleTest extends AccessTestBase {
|
|||
// Test allowing multiple roles.
|
||||
$view = Views::getView('test_access_role')->storage;
|
||||
$display = &$view->getDisplay('default');
|
||||
$display['display_options']['access']['options']['role'] = array(
|
||||
$display['display_options']['access']['options']['role'] = [
|
||||
$this->normalRole => $this->normalRole,
|
||||
'anonymous' => 'anonymous',
|
||||
);
|
||||
];
|
||||
$view->save();
|
||||
$this->container->get('router.builder')->rebuildIfNeeded();
|
||||
|
||||
|
@ -102,9 +102,9 @@ class AccessRoleTest extends AccessTestBase {
|
|||
$display['display_options']['cache'] = [
|
||||
'type' => 'tag',
|
||||
];
|
||||
$display['display_options']['access']['options']['role'] = array(
|
||||
$display['display_options']['access']['options']['role'] = [
|
||||
$this->normalRole => $this->normalRole,
|
||||
);
|
||||
];
|
||||
$view->save();
|
||||
|
||||
/** @var \Drupal\Core\Render\RendererInterface $renderer */
|
||||
|
|
|
@ -18,14 +18,14 @@ class AccessRoleUITest extends UITestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_access_role');
|
||||
public static $testViews = ['test_access_role'];
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('user', 'user_test_views');
|
||||
public static $modules = ['user', 'user_test_views'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -33,7 +33,7 @@ class AccessRoleUITest extends UITestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
ViewTestData::createTestViews(get_class($this), array('user_test_views'));
|
||||
ViewTestData::createTestViews(get_class($this), ['user_test_views']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -41,20 +41,20 @@ class AccessRoleUITest extends UITestBase {
|
|||
*/
|
||||
public function testAccessRoleUI() {
|
||||
$entity_manager = $this->container->get('entity.manager');
|
||||
$entity_manager->getStorage('user_role')->create(array('id' => 'custom_role', 'label' => 'Custom role'))->save();
|
||||
$entity_manager->getStorage('user_role')->create(['id' => 'custom_role', 'label' => 'Custom role'])->save();
|
||||
$access_url = "admin/structure/views/nojs/display/test_access_role/default/access_options";
|
||||
$this->drupalPostForm($access_url, array('access_options[role][custom_role]' => 1), t('Apply'));
|
||||
$this->drupalPostForm($access_url, ['access_options[role][custom_role]' => 1], t('Apply'));
|
||||
$this->assertResponse(200);
|
||||
|
||||
$this->drupalPostForm(NULL, array(), t('Save'));
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
$view = $entity_manager->getStorage('view')->load('test_access_role');
|
||||
|
||||
$display = $view->getDisplay('default');
|
||||
$this->assertEqual($display['display_options']['access']['options']['role'], array('custom_role' => 'custom_role'));
|
||||
$this->assertEqual($display['display_options']['access']['options']['role'], ['custom_role' => 'custom_role']);
|
||||
|
||||
// Test changing access plugin from role to none.
|
||||
$this->drupalPostForm('admin/structure/views/nojs/display/test_access_role/default/access', ['access[type]' => 'none'], t('Apply'));
|
||||
$this->drupalPostForm(NULL, array(), t('Save'));
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
// Verify that role option is not set.
|
||||
$view = $entity_manager->getStorage('view')->load('test_access_role');
|
||||
$display = $view->getDisplay('default');
|
||||
|
|
|
@ -12,7 +12,7 @@ abstract class AccessTestBase extends UserTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block');
|
||||
public static $modules = ['block'];
|
||||
|
||||
/**
|
||||
* Contains a user object that has no special permissions.
|
||||
|
@ -55,8 +55,8 @@ abstract class AccessTestBase extends UserTestBase {
|
|||
$roles = $this->webUser->getRoles();
|
||||
$this->webRole = $roles[0];
|
||||
|
||||
$this->normalRole = $this->drupalCreateRole(array());
|
||||
$this->normalUser = $this->drupalCreateUser(array('views_test_data test permission'));
|
||||
$this->normalRole = $this->drupalCreateRole([]);
|
||||
$this->normalUser = $this->drupalCreateUser(['views_test_data test permission']);
|
||||
$this->normalUser->addRole($this->normalRole);
|
||||
$this->normalUser->save();
|
||||
// @todo when all the plugin information is cached make a reset function and
|
||||
|
|
|
@ -16,7 +16,7 @@ class ArgumentDefaultTest extends UserTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_plugin_argument_default_current_user');
|
||||
public static $testViews = ['test_plugin_argument_default_current_user'];
|
||||
|
||||
public function test_plugin_argument_default_current_user() {
|
||||
// Create a user to test.
|
||||
|
|
|
@ -18,7 +18,7 @@ class ArgumentValidateTest extends UserTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_view_argument_validate_user', 'test_view_argument_validate_username');
|
||||
public static $testViews = ['test_view_argument_validate_user', 'test_view_argument_validate_username'];
|
||||
|
||||
/**
|
||||
* A user for this test.
|
||||
|
@ -36,7 +36,7 @@ class ArgumentValidateTest extends UserTestBase {
|
|||
/**
|
||||
* Tests the User (ID) argument validator.
|
||||
*/
|
||||
function testArgumentValidateUserUid() {
|
||||
public function testArgumentValidateUserUid() {
|
||||
$account = $this->account;
|
||||
|
||||
$view = Views::getView('test_view_argument_validate_user');
|
||||
|
@ -48,7 +48,7 @@ class ArgumentValidateTest extends UserTestBase {
|
|||
// Fail for a valid numeric, but for a user that doesn't exist
|
||||
$this->assertFalse($view->argument['null']->validateArgument(32));
|
||||
|
||||
$form = array();
|
||||
$form = [];
|
||||
$form_state = new FormState();
|
||||
$view->argument['null']->buildOptionsForm($form, $form_state);
|
||||
$sanitized_id = ArgumentPluginBase::encodeValidatorId('entity:user');
|
||||
|
|
|
@ -18,26 +18,26 @@ class BulkFormAccessTest extends UserTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('user_access_test');
|
||||
public static $modules = ['user_access_test'];
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_user_bulk_form');
|
||||
public static $testViews = ['test_user_bulk_form'];
|
||||
|
||||
/**
|
||||
* Tests if users that may not be edited, can not be edited in bulk.
|
||||
*/
|
||||
public function testUserEditAccess() {
|
||||
// Create an authenticated user.
|
||||
$no_edit_user = $this->drupalCreateUser(array(), 'no_edit');
|
||||
$no_edit_user = $this->drupalCreateUser([], 'no_edit');
|
||||
// Ensure this account is not blocked.
|
||||
$this->assertFalse($no_edit_user->isBlocked(), 'The user is not blocked.');
|
||||
|
||||
// Log in as user admin.
|
||||
$admin_user = $this->drupalCreateUser(array('administer users'));
|
||||
$admin_user = $this->drupalCreateUser(['administer users']);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
// Ensure that the account "no_edit" can not be edited.
|
||||
|
@ -46,10 +46,10 @@ class BulkFormAccessTest extends UserTestBase {
|
|||
$this->assertResponse(403, 'The user may not be edited.');
|
||||
|
||||
// Test blocking the account "no_edit".
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'user_bulk_form[' . ($no_edit_user->id() - 1) . ']' => TRUE,
|
||||
'action' => 'user_block_user_action',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('test-user-bulk-form', $edit, t('Apply to selected items'));
|
||||
$this->assertResponse(200);
|
||||
|
||||
|
@ -67,10 +67,10 @@ class BulkFormAccessTest extends UserTestBase {
|
|||
$normal_user = $this->drupalCreateUser();
|
||||
$this->assertTrue($normal_user->access('update', $admin_user));
|
||||
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'user_bulk_form[' . ($normal_user->id() - 1) . ']' => TRUE,
|
||||
'action' => 'user_block_user_action',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('test-user-bulk-form', $edit, t('Apply to selected items'));
|
||||
|
||||
$normal_user = User::load($normal_user->id());
|
||||
|
@ -79,10 +79,10 @@ class BulkFormAccessTest extends UserTestBase {
|
|||
// Log in as user without the 'administer users' permission.
|
||||
$this->drupalLogin($this->drupalCreateUser());
|
||||
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'user_bulk_form[' . ($normal_user->id() - 1) . ']' => TRUE,
|
||||
'action' => 'user_unblock_user_action',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('test-user-bulk-form', $edit, t('Apply to selected items'));
|
||||
|
||||
// Re-load the normal user and ensure it is still blocked.
|
||||
|
@ -95,11 +95,11 @@ class BulkFormAccessTest extends UserTestBase {
|
|||
*/
|
||||
public function testUserDeleteAccess() {
|
||||
// Create two authenticated users.
|
||||
$account = $this->drupalCreateUser(array(), 'no_delete');
|
||||
$account2 = $this->drupalCreateUser(array(), 'may_delete');
|
||||
$account = $this->drupalCreateUser([], 'no_delete');
|
||||
$account2 = $this->drupalCreateUser([], 'may_delete');
|
||||
|
||||
// Log in as user admin.
|
||||
$this->drupalLogin($this->drupalCreateUser(array('administer users')));
|
||||
$this->drupalLogin($this->drupalCreateUser(['administer users']));
|
||||
|
||||
// Ensure that the account "no_delete" can not be deleted.
|
||||
$this->drupalGet('user/' . $account->id() . '/cancel');
|
||||
|
@ -109,15 +109,15 @@ class BulkFormAccessTest extends UserTestBase {
|
|||
$this->assertResponse(200, 'The user "may_delete" may be deleted.');
|
||||
|
||||
// Test deleting the accounts "no_delete" and "may_delete".
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'user_bulk_form[' . ($account->id() - 1) . ']' => TRUE,
|
||||
'user_bulk_form[' . ($account2->id() - 1) . ']' => TRUE,
|
||||
'action' => 'user_cancel_user_action',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('test-user-bulk-form', $edit, t('Apply to selected items'));
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'user_cancel_method' => 'user_cancel_delete',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Cancel accounts'));
|
||||
|
||||
// Ensure the account "no_delete" still exists.
|
||||
|
|
|
@ -19,33 +19,33 @@ class BulkFormTest extends UserTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('views_ui');
|
||||
public static $modules = ['views_ui'];
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_user_bulk_form', 'test_user_bulk_form_combine_filter');
|
||||
public static $testViews = ['test_user_bulk_form', 'test_user_bulk_form_combine_filter'];
|
||||
|
||||
/**
|
||||
* Tests the user bulk form.
|
||||
*/
|
||||
public function testBulkForm() {
|
||||
// Log in as a user without 'administer users'.
|
||||
$this->drupalLogin($this->drupalCreateUser(array('administer permissions')));
|
||||
$this->drupalLogin($this->drupalCreateUser(['administer permissions']));
|
||||
$user_storage = $this->container->get('entity.manager')->getStorage('user');
|
||||
|
||||
// Create an user which actually can change users.
|
||||
$this->drupalLogin($this->drupalCreateUser(array('administer users')));
|
||||
$this->drupalLogin($this->drupalCreateUser(['administer users']));
|
||||
$this->drupalGet('test-user-bulk-form');
|
||||
$result = $this->cssSelect('#edit-action option');
|
||||
$this->assertTrue(count($result) > 0);
|
||||
|
||||
// Test submitting the page with no selection.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'action' => 'user_block_user_action',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('test-user-bulk-form', $edit, t('Apply to selected items'));
|
||||
$this->assertText(t('No users selected.'));
|
||||
|
||||
|
@ -56,36 +56,36 @@ class BulkFormTest extends UserTestBase {
|
|||
$role = key($roles);
|
||||
|
||||
$this->assertFalse($account->hasRole($role), 'The user currently does not have a custom role.');
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'user_bulk_form[1]' => TRUE,
|
||||
'action' => 'user_add_role_action.' . $role,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply to selected items'));
|
||||
// Re-load the user and check their roles.
|
||||
$user_storage->resetCache(array($account->id()));
|
||||
$user_storage->resetCache([$account->id()]);
|
||||
$account = $user_storage->load($account->id());
|
||||
$this->assertTrue($account->hasRole($role), 'The user now has the custom role.');
|
||||
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'user_bulk_form[1]' => TRUE,
|
||||
'action' => 'user_remove_role_action.' . $role,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply to selected items'));
|
||||
// Re-load the user and check their roles.
|
||||
$user_storage->resetCache(array($account->id()));
|
||||
$user_storage->resetCache([$account->id()]);
|
||||
$account = $user_storage->load($account->id());
|
||||
$this->assertFalse($account->hasRole($role), 'The user no longer has the custom role.');
|
||||
|
||||
// Block a user using the bulk form.
|
||||
$this->assertTrue($account->isActive(), 'The user is not blocked.');
|
||||
$this->assertRaw($account->label(), 'The user is found in the table.');
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'user_bulk_form[1]' => TRUE,
|
||||
'action' => 'user_block_user_action',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply to selected items'));
|
||||
// Re-load the user and check their status.
|
||||
$user_storage->resetCache(array($account->id()));
|
||||
$user_storage->resetCache([$account->id()]);
|
||||
$account = $user_storage->load($account->id());
|
||||
$this->assertTrue($account->isBlocked(), 'The user is blocked.');
|
||||
$this->assertNoRaw($account->label(), 'The user is not found in the table.');
|
||||
|
@ -100,16 +100,16 @@ class BulkFormTest extends UserTestBase {
|
|||
$this->assertText($this->config('user.settings')->get('anonymous'));
|
||||
|
||||
// Attempt to block the anonymous user.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'user_bulk_form[0]' => TRUE,
|
||||
'action' => 'user_block_user_action',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Apply to selected items'));
|
||||
$anonymous_account = $user_storage->load(0);
|
||||
$this->assertTrue($anonymous_account->isBlocked(), 'Ensure the anonymous user got blocked.');
|
||||
|
||||
// Test the list of available actions with a value that contains a dot.
|
||||
$this->drupalLogin($this->drupalCreateUser(array('administer permissions', 'administer views', 'administer users')));
|
||||
$this->drupalLogin($this->drupalCreateUser(['administer permissions', 'administer views', 'administer users']));
|
||||
$action_id = 'user_add_role_action.' . $role;
|
||||
$edit = [
|
||||
'options[include_exclude]' => 'exclude',
|
||||
|
@ -134,7 +134,7 @@ class BulkFormTest extends UserTestBase {
|
|||
User::load($this->users[0]->id());
|
||||
$view = Views::getView('test_user_bulk_form_combine_filter');
|
||||
$errors = $view->validate();
|
||||
$this->assertEqual(reset($errors['default']), t('Field %field set in %filter is not usable for this filter type. Combined field filter only works for simple fields.', array('%field' => 'User: Bulk update', '%filter' => 'Global: Combine fields filter')));
|
||||
$this->assertEqual(reset($errors['default']), t('Field %field set in %filter is not usable for this filter type. Combined field filter only works for simple fields.', ['%field' => 'User: Bulk update', '%filter' => 'Global: Combine fields filter']));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ class FilterPermissionUiTest extends ViewTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp(TRUE);
|
||||
|
||||
ViewTestData::createTestViews(get_class($this), array('user_test_views'));
|
||||
ViewTestData::createTestViews(get_class($this), ['user_test_views']);
|
||||
$this->enableViewsTestModule();
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ class HandlerArgumentUserUidTest extends UserTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_user_uid_argument');
|
||||
public static $testViews = ['test_user_uid_argument'];
|
||||
|
||||
/**
|
||||
* Tests the generated title of an user: uid argument.
|
||||
|
@ -25,29 +25,29 @@ class HandlerArgumentUserUidTest extends UserTestBase {
|
|||
$view = Views::getView('test_user_uid_argument');
|
||||
|
||||
// Tests an invalid user uid.
|
||||
$this->executeView($view, array(rand(1000, 10000)));
|
||||
$this->executeView($view, [rand(1000, 10000)]);
|
||||
$this->assertFalse($view->getTitle());
|
||||
$view->destroy();
|
||||
|
||||
// Tests a valid user.
|
||||
$account = $this->drupalCreateUser();
|
||||
$this->executeView($view, array($account->id()));
|
||||
$this->executeView($view, [$account->id()]);
|
||||
$this->assertEqual($view->getTitle(), $account->label());
|
||||
$view->destroy();
|
||||
|
||||
// Tests the anonymous user.
|
||||
$anonymous = $this->config('user.settings')->get('anonymous');
|
||||
$this->executeView($view, array(0));
|
||||
$this->executeView($view, [0]);
|
||||
$this->assertEqual($view->getTitle(), $anonymous);
|
||||
$view->destroy();
|
||||
|
||||
$view->getDisplay()->getHandler('argument', 'uid')->options['break_phrase'] = TRUE;
|
||||
$this->executeView($view, array($account->id() . ',0'));
|
||||
$this->executeView($view, [$account->id() . ',0']);
|
||||
$this->assertEqual($view->getTitle(), $account->label() . ', ' . $anonymous);
|
||||
$view->destroy();
|
||||
|
||||
$view->getDisplay()->getHandler('argument', 'uid')->options['break_phrase'] = TRUE;
|
||||
$this->executeView($view, array('0,' . $account->id()));
|
||||
$this->executeView($view, ['0,' . $account->id()]);
|
||||
$this->assertEqual($view->getTitle(), $anonymous . ', ' . $account->label());
|
||||
$view->destroy();
|
||||
}
|
||||
|
|
|
@ -18,18 +18,18 @@ class HandlerFieldRoleTest extends UserTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_views_handler_field_role');
|
||||
public static $testViews = ['test_views_handler_field_role'];
|
||||
|
||||
public function testRole() {
|
||||
// Create a couple of roles for the view.
|
||||
$rolename_a = 'a' . $this->randomMachineName(8);
|
||||
$this->drupalCreateRole(array('access content'), $rolename_a, '<em>' . $rolename_a . '</em>', 9);
|
||||
$this->drupalCreateRole(['access content'], $rolename_a, '<em>' . $rolename_a . '</em>', 9);
|
||||
|
||||
$rolename_b = 'b' . $this->randomMachineName(8);
|
||||
$this->drupalCreateRole(array('access content'), $rolename_b, $rolename_b, 8);
|
||||
$this->drupalCreateRole(['access content'], $rolename_b, $rolename_b, 8);
|
||||
|
||||
$rolename_not_assigned = $this->randomMachineName(8);
|
||||
$this->drupalCreateRole(array('access content'), $rolename_not_assigned, $rolename_not_assigned);
|
||||
$this->drupalCreateRole(['access content'], $rolename_not_assigned, $rolename_not_assigned);
|
||||
|
||||
// Add roles to user 1.
|
||||
$user = User::load(1);
|
||||
|
|
|
@ -18,13 +18,13 @@ class HandlerFieldUserNameTest extends UserTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_views_handler_field_user_name');
|
||||
public static $testViews = ['test_views_handler_field_user_name'];
|
||||
|
||||
public function testUserName() {
|
||||
/** @var \Drupal\Core\Render\RendererInterface $renderer */
|
||||
$renderer = \Drupal::service('renderer');
|
||||
|
||||
$new_user = $this->drupalCreateUser(array('access user profiles'));
|
||||
$new_user = $this->drupalCreateUser(['access user profiles']);
|
||||
$this->drupalLogin($new_user);
|
||||
|
||||
// Set defaults.
|
||||
|
|
|
@ -19,47 +19,47 @@ class HandlerFilterUserNameTest extends ViewTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('views_ui', 'user_test_views');
|
||||
public static $modules = ['views_ui', 'user_test_views'];
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_user_name');
|
||||
public static $testViews = ['test_user_name'];
|
||||
|
||||
/**
|
||||
* Accounts used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $accounts = array();
|
||||
protected $accounts = [];
|
||||
|
||||
/**
|
||||
* Usernames of $accounts.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $names = array();
|
||||
protected $names = [];
|
||||
|
||||
/**
|
||||
* Stores the column map for this testCase.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $columnMap = array(
|
||||
public $columnMap = [
|
||||
'uid' => 'uid',
|
||||
);
|
||||
];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
ViewTestData::createTestViews(get_class($this), array('user_test_views'));
|
||||
ViewTestData::createTestViews(get_class($this), ['user_test_views']);
|
||||
|
||||
$this->enableViewsTestModule();
|
||||
|
||||
$this->accounts = array();
|
||||
$this->names = array();
|
||||
$this->accounts = [];
|
||||
$this->names = [];
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$this->accounts[] = $account = $this->drupalCreateUser();
|
||||
$this->names[] = $account->label();
|
||||
|
@ -74,10 +74,10 @@ class HandlerFilterUserNameTest extends ViewTestBase {
|
|||
$view = Views::getView('test_user_name');
|
||||
|
||||
$view->initHandlers();
|
||||
$view->filter['uid']->value = array($this->accounts[0]->id());
|
||||
$view->filter['uid']->value = [$this->accounts[0]->id()];
|
||||
|
||||
$this->executeView($view);
|
||||
$this->assertIdenticalResultset($view, array(array('uid' => $this->accounts[0]->id())), $this->columnMap);
|
||||
$this->assertIdenticalResultset($view, [['uid' => $this->accounts[0]->id()]], $this->columnMap);
|
||||
|
||||
$this->assertEqual($view->filter['uid']->getValueOptions(), NULL);
|
||||
}
|
||||
|
@ -86,40 +86,40 @@ class HandlerFilterUserNameTest extends ViewTestBase {
|
|||
* Tests using the user interface.
|
||||
*/
|
||||
public function testAdminUserInterface() {
|
||||
$admin_user = $this->drupalCreateUser(array('administer views', 'administer site configuration'));
|
||||
$admin_user = $this->drupalCreateUser(['administer views', 'administer site configuration']);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
$path = 'admin/structure/views/nojs/handler/test_user_name/default/filter/uid';
|
||||
$this->drupalGet($path);
|
||||
|
||||
// Pass in an invalid username, the validation should catch it.
|
||||
$users = array($this->randomMachineName());
|
||||
$users = [$this->randomMachineName()];
|
||||
$users = array_map('strtolower', $users);
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'options[value]' => implode(', ', $users)
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm($path, $edit, t('Apply'));
|
||||
$this->assertRaw(t('There are no entities matching "%value".', array('%value' => implode(', ', $users))));
|
||||
$this->assertRaw(t('There are no entities matching "%value".', ['%value' => implode(', ', $users)]));
|
||||
|
||||
// Pass in an invalid username and a valid username.
|
||||
$random_name = $this->randomMachineName();
|
||||
$users = array($random_name, $this->names[0]);
|
||||
$users = [$random_name, $this->names[0]];
|
||||
$users = array_map('strtolower', $users);
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'options[value]' => implode(', ', $users)
|
||||
);
|
||||
$users = array($users[0]);
|
||||
];
|
||||
$users = [$users[0]];
|
||||
$this->drupalPostForm($path, $edit, t('Apply'));
|
||||
$this->assertRaw(t('There are no entities matching "%value".', array('%value' => implode(', ', $users))));
|
||||
$this->assertRaw(t('There are no entities matching "%value".', ['%value' => implode(', ', $users)]));
|
||||
|
||||
// Pass in just valid usernames.
|
||||
$users = $this->names;
|
||||
$users = array_map('strtolower', $users);
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'options[value]' => implode(', ', $users)
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm($path, $edit, t('Apply'));
|
||||
$this->assertNoRaw(t('There are no entities matching "%value".', array('%value' => implode(', ', $users))));
|
||||
$this->assertNoRaw(t('There are no entities matching "%value".', ['%value' => implode(', ', $users)]));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -128,14 +128,14 @@ class HandlerFilterUserNameTest extends ViewTestBase {
|
|||
public function testExposedFilter() {
|
||||
$path = 'test_user_name';
|
||||
|
||||
$options = array();
|
||||
$options = [];
|
||||
|
||||
// Pass in an invalid username, the validation should catch it.
|
||||
$users = array($this->randomMachineName());
|
||||
$users = [$this->randomMachineName()];
|
||||
$users = array_map('strtolower', $users);
|
||||
$options['query']['uid'] = implode(', ', $users);
|
||||
$this->drupalGet($path, $options);
|
||||
$this->assertRaw(t('There are no entities matching "%value".', array('%value' => implode(', ', $users))));
|
||||
$this->assertRaw(t('There are no entities matching "%value".', ['%value' => implode(', ', $users)]));
|
||||
|
||||
// Pass in an invalid target_id in for the entity_autocomplete value format.
|
||||
// There should be no errors, but all results should be returned as the
|
||||
|
@ -149,13 +149,13 @@ class HandlerFilterUserNameTest extends ViewTestBase {
|
|||
}
|
||||
|
||||
// Pass in an invalid username and a valid username.
|
||||
$users = array($this->randomMachineName(), $this->names[0]);
|
||||
$users = [$this->randomMachineName(), $this->names[0]];
|
||||
$users = array_map('strtolower', $users);
|
||||
$options['query']['uid'] = implode(', ', $users);
|
||||
$users = array($users[0]);
|
||||
$users = [$users[0]];
|
||||
|
||||
$this->drupalGet($path, $options);
|
||||
$this->assertRaw(t('There are no entities matching "%value".', array('%value' => implode(', ', $users))));
|
||||
$this->assertRaw(t('There are no entities matching "%value".', ['%value' => implode(', ', $users)]));
|
||||
|
||||
// Pass in just valid usernames.
|
||||
$users = $this->names;
|
||||
|
|
|
@ -16,7 +16,7 @@ class RelationshipRepresentativeNodeTest extends UserTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_groupwise_user');
|
||||
public static $testViews = ['test_groupwise_user'];
|
||||
|
||||
/**
|
||||
* Tests the relationship.
|
||||
|
@ -24,17 +24,17 @@ class RelationshipRepresentativeNodeTest extends UserTestBase {
|
|||
public function testRelationship() {
|
||||
$view = Views::getView('test_groupwise_user');
|
||||
$this->executeView($view);
|
||||
$map = array('node_field_data_users_field_data_nid' => 'nid', 'uid' => 'uid');
|
||||
$expected_result = array(
|
||||
array(
|
||||
$map = ['node_field_data_users_field_data_nid' => 'nid', 'uid' => 'uid'];
|
||||
$expected_result = [
|
||||
[
|
||||
'uid' => $this->users[1]->id(),
|
||||
'nid' => $this->nodes[1]->id(),
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'uid' => $this->users[0]->id(),
|
||||
'nid' => $this->nodes[0]->id(),
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
$this->assertIdenticalResultset($view, $expected_result, $map);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ class RolesRidArgumentTest extends UserTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_user_roles_rid');
|
||||
public static $testViews = ['test_user_roles_rid'];
|
||||
|
||||
/**
|
||||
* Tests the generated title of a user: roles argument.
|
||||
|
|
|
@ -17,19 +17,19 @@ class UserChangedTest extends ViewTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('views_ui', 'user_test_views');
|
||||
public static $modules = ['views_ui', 'user_test_views'];
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_user_changed');
|
||||
public static $testViews = ['test_user_changed'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
ViewTestData::createTestViews(get_class($this), array('user_test_views'));
|
||||
ViewTestData::createTestViews(get_class($this), ['user_test_views']);
|
||||
|
||||
$this->enableViewsTestModule();
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ class UserChangedTest extends ViewTestBase {
|
|||
public function testChangedField() {
|
||||
$path = 'test_user_changed';
|
||||
|
||||
$options = array();
|
||||
$options = [];
|
||||
|
||||
$this->drupalGet($path, $options);
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Reference in a new issue