diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php index cb1fe970b4c4d504b8569838254506e8c6a12665..3bd7269faf910424bc1132b275b2d10aa11a32a0 100644 --- a/core/modules/simpletest/src/WebTestBase.php +++ b/core/modules/simpletest/src/WebTestBase.php @@ -621,7 +621,7 @@ protected function drupalCreateRole(array $permissions, $rid = NULL, $name = NUL // Grant the specified permissions to the role, if any. if (!empty($permissions)) { user_role_grant_permissions($role->id(), $permissions); - $assigned_permissions = entity_load('user_role', $role->id())->permissions; + $assigned_permissions = entity_load('user_role', $role->id())->getPermissions(); $missing_permissions = array_diff($permissions, $assigned_permissions); if (!$missing_permissions) { $this->pass(String::format('Created permissions: @perms', array('@perms' => implode(', ', $permissions))), 'Role'); diff --git a/core/modules/user/src/Entity/Role.php b/core/modules/user/src/Entity/Role.php index b517ac940996e31a19ed4fe1a18770b41b3f8000..e02c97a9b49124d49830342de6cceb67e8ea2a9a 100644 --- a/core/modules/user/src/Entity/Role.php +++ b/core/modules/user/src/Entity/Role.php @@ -47,28 +47,28 @@ class Role extends ConfigEntityBase implements RoleInterface { * * @var string */ - public $id; + protected $id; /** * The human-readable label of this role. * * @var string */ - public $label; + protected $label; /** * The weight of this role in administrative listings. * * @var int */ - public $weight; + protected $weight; /** * The permissions belonging to this role. * * @var array */ - public $permissions = array(); + protected $permissions = array(); /** * {@inheritdoc} @@ -77,6 +77,21 @@ public function getPermissions() { return $this->permissions; } + /** + * {@inheritdoc} + */ + public function getWeight() { + return $this->get('weight'); + } + + /** + * {@inheritdoc} + */ + public function setWeight($weight) { + $this->set('weight', $weight); + return $this; + } + /** * {@inheritdoc} */ diff --git a/core/modules/user/src/RoleForm.php b/core/modules/user/src/RoleForm.php index 2bed647ac6e7b3ad499eff428557fad9cc376c20..1961a758d29ac61e87f9522dc747a91e5b665601 100644 --- a/core/modules/user/src/RoleForm.php +++ b/core/modules/user/src/RoleForm.php @@ -42,7 +42,7 @@ public function form(array $form, array &$form_state) { ); $form['weight'] = array( '#type' => 'value', - '#value' => $entity->get('weight'), + '#value' => $entity->getWeight(), ); return parent::form($form, $form_state, $entity); diff --git a/core/modules/user/src/RoleInterface.php b/core/modules/user/src/RoleInterface.php index 1cae601ba9affa6bf35f6e4b42e8aff11b30bcba..f1d76eea29bd00292d9887cc698376f91fb59e1d 100644 --- a/core/modules/user/src/RoleInterface.php +++ b/core/modules/user/src/RoleInterface.php @@ -41,8 +41,7 @@ public function hasPermission($permission); * @param string $permission * The permission to grant. * - * @return RoleInterface - * The called object for chaining. + * @return $this */ public function grantPermission($permission); @@ -52,9 +51,26 @@ public function grantPermission($permission); * @param string $permission * The permission to revoke. * - * @return RoleInterface - * The called object for chaining. + * @return $this */ public function revokePermission($permission); + /** + * Returns the weight. + * + * @return int + * The weight of this role. + */ + public function getWeight(); + + /** + * Sets the weight to the given value. + * + * @param int $weight + * The desired weight. + * + * @return $this + */ + public function setWeight($weight); + } diff --git a/core/modules/user/src/Tests/UserRoleAdminTest.php b/core/modules/user/src/Tests/UserRoleAdminTest.php index 43ecaef21b2332452e92494aa36465ab628f48b0..bf9d88ccc731acc284fa6afcfdb183317dc32581 100644 --- a/core/modules/user/src/Tests/UserRoleAdminTest.php +++ b/core/modules/user/src/Tests/UserRoleAdminTest.php @@ -92,9 +92,9 @@ function testRoleWeightOrdering() { // Change the role weights to make the roles in reverse order. $edit = array(); foreach ($roles as $role) { - $edit['entities['. $role->id() .'][weight]'] = $weight; + $edit['entities[' . $role->id() . '][weight]'] = $weight; $new_role_weights[$role->id()] = $weight; - $saved_rids[] = $role->id; + $saved_rids[] = $role->id(); $weight--; } $this->drupalPostForm('admin/people/roles', $edit, t('Save order')); @@ -106,8 +106,8 @@ function testRoleWeightOrdering() { $rids = array(); // Test that the role weights have been correctly saved. foreach ($roles as $role) { - $this->assertEqual($role->weight, $new_role_weights[$role->id()]); - $rids[] = $role->id; + $this->assertEqual($role->getWeight(), $new_role_weights[$role->id()]); + $rids[] = $role->id(); } // The order of the roles should be reversed. $this->assertIdentical($rids, array_reverse($saved_rids));