summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2014-07-11 11:15:22 (GMT)
committerNathaniel Catchpole2014-07-11 11:15:22 (GMT)
commit028920c17f5201cd88617757e8f0f41d71bb8724 (patch)
treeb7e84e47e62fc58723886a49b54fd9d6f54f6a40
parent837d726fea21a57d43fc31150e80a0056c4022bc (diff)
Issue #2030655 by justafish, Alumei, daffie, alexpott, wwhurley, jamesquinton, pcambra, InternetDevels, rdatar, james_kerrigan: Expand Role with methods.
-rw-r--r--core/modules/simpletest/src/WebTestBase.php2
-rw-r--r--core/modules/user/src/Entity/Role.php23
-rw-r--r--core/modules/user/src/RoleForm.php2
-rw-r--r--core/modules/user/src/RoleInterface.php24
-rw-r--r--core/modules/user/src/Tests/UserRoleAdminTest.php8
5 files changed, 45 insertions, 14 deletions
diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php
index cb1fe97..3bd7269 100644
--- a/core/modules/simpletest/src/WebTestBase.php
+++ b/core/modules/simpletest/src/WebTestBase.php
@@ -621,7 +621,7 @@ abstract class WebTestBase extends TestBase {
// 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 @@ class Role extends ConfigEntityBase implements RoleInterface {
/**
* {@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 @@ class RoleForm extends EntityForm {
);
$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 1cae601..f1d76ee 100644
--- a/core/modules/user/src/RoleInterface.php
+++ b/core/modules/user/src/RoleInterface.php
@@ -41,8 +41,7 @@ interface RoleInterface extends ConfigEntityInterface {
* @param string $permission
* The permission to grant.
*
- * @return RoleInterface
- * The called object for chaining.
+ * @return $this
*/
public function grantPermission($permission);
@@ -52,9 +51,26 @@ interface RoleInterface extends ConfigEntityInterface {
* @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 43ecaef..bf9d88c 100644
--- a/core/modules/user/src/Tests/UserRoleAdminTest.php
+++ b/core/modules/user/src/Tests/UserRoleAdminTest.php
@@ -92,9 +92,9 @@ class UserRoleAdminTest extends WebTestBase {
// 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 @@ class UserRoleAdminTest extends WebTestBase {
$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));