diff --git a/roleassign.module b/roleassign.module index f646a65..d871d46 100755 --- a/roleassign.module +++ b/roleassign.module @@ -38,12 +38,12 @@ function roleassign_help($route_name, RouteMatchInterface $route_match) {
  1. Log in as a user with both the Assign roles and the Administer users permissions.
  2. To change the roles of a user, go to the user\'s account and review the assignable roles and change them as necessary.
  3. -
', array( + ', [ ':user_protect' => 'http://drupal.org/project/userprotect', - ) + ] ); case 'roleassign.settings': - return t('Users with both %administer_users and %assign_roles permissions are allowed to assign the roles selected below. For more information, see the help page.', array('%administer_users' => $permissions['administer users']['title'], '%assign_roles' => $permissions['assign roles']['title'], ':help' => Url::fromRoute('help.page', ['name' => 'roleassign'])->toString())); + return t('Users with both %administer_users and %assign_roles permissions are allowed to assign the roles selected below. For more information, see the help page.', ['%administer_users' => $permissions['administer users']['title'], '%assign_roles' => $permissions['assign roles']['title'], ':help' => Url::fromRoute('help.page', ['name' => 'roleassign'])->toString()]); } } @@ -100,16 +100,16 @@ function roleassign_form_alter(&$form, FormStateInterface $form_state, $form_id) $sticky_roles[RoleInterface::AUTHENTICATED_ID] = $roles[RoleInterface::AUTHENTICATED_ID]; // Store sticky roles in form values. - $form['sticky_roles'] = array('#type' => 'value', '#value' => $sticky_roles); + $form['sticky_roles'] = ['#type' => 'value', '#value' => $sticky_roles]; // Build the assign roles checkboxes. - $roles_field = array( + $roles_field = [ '#type' => 'checkboxes', '#title' => t('Assignable roles'), '#options' => $assignable_roles, - '#default_value' => empty($assigned_roles) ? array() : array_keys($assigned_roles), - '#description' => t('The user receives the combined permissions of all roles selected here and the following roles: %roles.', array('%roles' => implode(', ', $sticky_roles))), - ); + '#default_value' => empty($assigned_roles) ? [] : array_keys($assigned_roles), + '#description' => t('The user receives the combined permissions of all roles selected here and the following roles: %roles.', ['%roles' => implode(', ', $sticky_roles)]), + ]; // The user form is sometimes within an 'account' fieldset. if (isset($form['account'])) { $user_form =&$form['account']; diff --git a/src/Form/RoleAssignAdminForm.php b/src/Form/RoleAssignAdminForm.php index d8a0336..2f34900 100644 --- a/src/Form/RoleAssignAdminForm.php +++ b/src/Form/RoleAssignAdminForm.php @@ -37,13 +37,13 @@ class RoleAssignAdminForm extends ConfigFormBase { // Show checkboxes with roles that can be delegated if any. if ($roles) { $config = $this->config('roleassign.settings'); - $form['roleassign_roles'] = array( + $form['roleassign_roles'] = [ '#type' => 'checkboxes', '#title' => $this->t('Roles'), '#default_value' => $config->get('roleassign_roles'), '#options' => $roles, '#description' => $this->t('Select roles that should be available for assignment.'), - ); + ]; } return parent::buildForm($form, $form_state); diff --git a/src/Plugin/views/field/RoleAssignUserBulkForm.php b/src/Plugin/views/field/RoleAssignUserBulkForm.php index d20067f..76cd50e 100644 --- a/src/Plugin/views/field/RoleAssignUserBulkForm.php +++ b/src/Plugin/views/field/RoleAssignUserBulkForm.php @@ -22,7 +22,7 @@ class RoleAssignUserBulkForm extends UserBulkForm { // Remove actions that are not allowed based on RoleAssign settings. $assignable_roles = array_filter(\Drupal::config('roleassign.settings')->get('roleassign_roles')); foreach ($this->actions as $action_key => $action) { - if (in_array($action->get('plugin'), array('user_add_role_action', 'user_remove_role_action'))) { + if (in_array($action->get('plugin'), ['user_add_role_action', 'user_remove_role_action'])) { $config = $action->get('configuration'); if (!in_array($config['rid'], $assignable_roles)) { unset($this->actions[$action_key]); diff --git a/tests/src/Functional/RoleAssignPermissionTest.php b/tests/src/Functional/RoleAssignPermissionTest.php index 3d543fe..87b8f25 100644 --- a/tests/src/Functional/RoleAssignPermissionTest.php +++ b/tests/src/Functional/RoleAssignPermissionTest.php @@ -51,16 +51,16 @@ class RoleAssignPermissionTest extends BrowserTestBase { parent::setUp(); // Add Editor role - $this->drupalCreateRole(array(), 'editor', 'Editor'); + $this->drupalCreateRole([], 'editor', 'Editor'); // Add Webmaster role - $this->drupalCreateRole(array('administer users', 'assign roles'), 'webmaster', 'Webmaster'); + $this->drupalCreateRole(['administer users', 'assign roles'], 'webmaster', 'Webmaster'); // Add 'protected' SiteAdmin role - $this->drupalCreateRole(array('administer users', 'administer permissions'), 'siteadmin', 'SiteAdmin'); + $this->drupalCreateRole(['administer users', 'administer permissions'], 'siteadmin', 'SiteAdmin'); // Configure RoleAssign module - only editor & webmaster roles are // assignable by restricted users (i.e. webmasters) $this->config('roleassign.settings') - ->set('roleassign_roles', array('editor' => 'editor', 'webmaster' => 'webmaster')) + ->set('roleassign_roles', ['editor' => 'editor', 'webmaster' => 'webmaster']) ->save(); // Create a testaccount that we will be trying to assign roles. @@ -68,12 +68,12 @@ class RoleAssignPermissionTest extends BrowserTestBase { // Create a test restricted user without "administer permissions" permission // but with "assign roles" permission provided by RoleAssign. - $this->restricted_user = $this->drupalCreateUser(array('administer users', 'assign roles')); + $this->restricted_user = $this->drupalCreateUser(['administer users', 'assign roles']); // Create a test admin user with "administer users " & // "administer permissions" permissions, where RoleAssign will have no // effect on. - $this->admin_user = $this->drupalCreateUser(array('administer users', 'administer permissions')); + $this->admin_user = $this->drupalCreateUser(['administer users', 'administer permissions']); } /** @@ -81,7 +81,7 @@ class RoleAssignPermissionTest extends BrowserTestBase { */ function testRoleAssignSettings() { $assignable_roles = array_filter(\Drupal::config('roleassign.settings')->get('roleassign_roles')); - $this->assertIdentical(array('editor' => 'editor', 'webmaster' => 'webmaster'), $assignable_roles); + $this->assertIdentical(['editor' => 'editor', 'webmaster' => 'webmaster'], $assignable_roles); } /** @@ -101,7 +101,7 @@ class RoleAssignPermissionTest extends BrowserTestBase { $this->assertNoField('edit-roles-siteadmin'); // Assign the role "editor" to the account. - $this->drupalPostForm('user/' . $this->testaccount->id() . '/edit', array("roles[editor]" => "editor"), t('Save')); + $this->drupalPostForm('user/' . $this->testaccount->id() . '/edit', ["roles[editor]" => "editor"], t('Save')); $this->assertText(t('The changes have been saved.')); $this->assertFieldChecked('edit-roles-editor', 'Role editor is assigned.'); $this->assertNoFieldChecked('edit-roles-webmaster'); @@ -110,7 +110,7 @@ class RoleAssignPermissionTest extends BrowserTestBase { $this->userLoadAndCheckRoleAssigned($this->testaccount, RoleInterface::AUTHENTICATED_ID); // Remove the role "editor" from the account. - $this->drupalPostForm('user/' . $this->testaccount->id() . '/edit', array("roles[editor]" => FALSE), t('Save')); + $this->drupalPostForm('user/' . $this->testaccount->id() . '/edit', ["roles[editor]" => FALSE], t('Save')); $this->assertText(t('The changes have been saved.')); $this->assertNoFieldChecked('edit-roles-editor', 'Role editor is removed.'); $this->assertNoFieldChecked('edit-roles-webmaster'); @@ -119,10 +119,10 @@ class RoleAssignPermissionTest extends BrowserTestBase { $this->userLoadAndCheckRoleAssigned($this->testaccount, RoleInterface::AUTHENTICATED_ID); // Try to assign a restricted role programmatically to a new user. - $values = array( + $values = [ 'name' => $this->randomString(), - 'roles' => array('editor', 'siteadmin'), - ); + 'roles' => ['editor', 'siteadmin'], + ]; $code_account = User::create($values); $code_account->save(); @@ -148,7 +148,7 @@ class RoleAssignPermissionTest extends BrowserTestBase { $this->assertNoFieldChecked('edit-roles-siteadmin'); // Assign the role "SiteAdmin" to the account. - $this->drupalPostForm('user/' . $this->testaccount->id() . '/edit', array("roles[siteadmin]" => "siteadmin"), t('Save')); + $this->drupalPostForm('user/' . $this->testaccount->id() . '/edit', ["roles[siteadmin]" => "siteadmin"], t('Save')); $this->assertText(t('The changes have been saved.')); $this->assertFieldChecked('edit-roles-siteadmin', 'Role siteadmin is assigned.'); $this->userLoadAndCheckRoleAssigned($this->testaccount, 'siteadmin'); @@ -159,7 +159,7 @@ class RoleAssignPermissionTest extends BrowserTestBase { // Assign the role "editor" to the account, and test that the assigned // "siteadmin" role doesn't get lost. - $this->drupalPostForm('user/' . $this->testaccount->id() . '/edit', array("roles[editor]" => "editor"), t('Save')); + $this->drupalPostForm('user/' . $this->testaccount->id() . '/edit', ["roles[editor]" => "editor"], t('Save')); $this->assertText(t('The changes have been saved.')); $this->assertFieldChecked('edit-roles-editor', 'Role editor is assigned.'); $this->assertNoField('edit-roles-siteadmin'); @@ -181,7 +181,7 @@ class RoleAssignPermissionTest extends BrowserTestBase { */ private function userLoadAndCheckRoleAssigned($account, $rid, $is_assigned = TRUE) { $user_storage = \Drupal::entityTypeManager()->getStorage('user'); - $user_storage->resetCache(array($account->id())); + $user_storage->resetCache([$account->id()]); $account = $user_storage->load($account->id()); if ($is_assigned) { $this->assertFalse(array_search($rid, $account->getRoles()) === FALSE, 'The role is present in the user object.');