diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php index 347ddb3..7d4a129 100644 --- a/core/modules/simpletest/src/WebTestBase.php +++ b/core/modules/simpletest/src/WebTestBase.php @@ -645,7 +645,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 b517ac9..e02c97a 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} @@ -80,6 +80,21 @@ public function getPermissions() { /** * {@inheritdoc} */ + public function getWeight() { + return $this->get('weight'); + } + + /** + * {@inheritdoc} + */ + public function setWeight($weight) { + $this->set('weight', $weight); + return $this; + } + + /** + * {@inheritdoc} + */ public function hasPermission($permission) { return in_array($permission, $this->permissions); } diff --git a/core/modules/user/src/RoleForm.php b/core/modules/user/src/RoleForm.php index 2bed647..1961a75 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 7160a8e..30a9e79 100644 --- a/core/modules/user/src/RoleInterface.php +++ b/core/modules/user/src/RoleInterface.php @@ -39,8 +39,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); @@ -50,9 +49,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 0ddfa73..2a704a5 100644 --- a/core/modules/user/src/Tests/UserRoleAdminTest.php +++ b/core/modules/user/src/Tests/UserRoleAdminTest.php @@ -98,9 +98,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')); @@ -112,8 +112,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));