Commit 331f2878 authored by alexpott's avatar alexpott

Issue #2322233 by Temoor, Mirroar, estoyausente: Replace all instances of...

Issue #2322233 by Temoor, Mirroar, estoyausente: Replace all instances of user_role_load(), entity_load('user_role') and entity_load_multiple('user_role') with static method calls.
parent 4fc159c6
......@@ -9,6 +9,7 @@
use Drupal\aggregator\Entity\Feed;
use Drupal\system\Tests\Entity\EntityWithUriCacheTagsTestBase;
use Drupal\user\Entity\Role;
/**
* Tests the Feed entity's cache tags.
......@@ -35,7 +36,7 @@ protected function setUp() {
// Give anonymous users permission to access feeds, so that we can verify
// the cache tags of cached versions of feeds.
$user_role = entity_load('user_role', DRUPAL_ANONYMOUS_RID);
$user_role = Role::load(DRUPAL_ANONYMOUS_RID);
$user_role->grantPermission('access news feeds');
$user_role->save();
}
......
......@@ -10,6 +10,7 @@
use Drupal\aggregator\Entity\Feed;
use Drupal\aggregator\Entity\Item;
use Drupal\system\Tests\Entity\EntityCacheTagsTestBase;
use Drupal\user\Entity\Role;
/**
* Tests the Item entity's cache tags.
......@@ -36,7 +37,7 @@ protected function setUp() {
// Give anonymous users permission to access feeds, so that we can verify
// the cache tags of cached versions of feed items.
$user_role = entity_load('user_role', DRUPAL_ANONYMOUS_RID);
$user_role = Role::load(DRUPAL_ANONYMOUS_RID);
$user_role->grantPermission('access news feeds');
$user_role->save();
}
......
......@@ -11,6 +11,7 @@
use Drupal\Core\Entity\EntityInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\system\Tests\Entity\EntityWithUriCacheTagsTestBase;
use Drupal\user\Entity\Role;
/**
* Tests the Comment entity's cache tags.
......@@ -32,7 +33,7 @@ protected function setUp() {
// Give anonymous users permission to view comments, so that we can verify
// the cache tags of cached versions of comment pages.
$user_role = entity_load('user_role', DRUPAL_ANONYMOUS_RID);
$user_role = Role::load(DRUPAL_ANONYMOUS_RID);
$user_role->grantPermission('access comments');
$user_role->save();
}
......
......@@ -9,6 +9,7 @@
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate_drupal\Tests\MigrateDrupalTestBase;
use Drupal\user\Entity\Role;
/**
* Upgrade user roles to user.role.*.yml.
......@@ -56,22 +57,22 @@ public function testUserRole() {
/** @var \Drupal\migrate\entity\Migration $migration */
$migration = entity_load('migration', 'd6_user_role');
$rid = 'anonymous';
$anonymous = entity_load('user_role', $rid);
$anonymous = Role::load($rid);
$this->assertEqual($anonymous->id(), $rid);
$this->assertEqual($anonymous->getPermissions(), array('migrate test anonymous permission', 'use text format filtered_html'));
$this->assertEqual(array($rid), $migration->getIdMap()->lookupDestinationId(array(1)));
$rid = 'authenticated';
$authenticated = entity_load('user_role', $rid);
$authenticated = Role::load($rid);
$this->assertEqual($authenticated->id(), $rid);
$this->assertEqual($authenticated->getPermissions(), array('migrate test authenticated permission', 'use text format filtered_html'));
$this->assertEqual(array($rid), $migration->getIdMap()->lookupDestinationId(array(2)));
$rid = 'migrate_test_role_1';
$migrate_test_role_1 = entity_load('user_role', $rid);
$migrate_test_role_1 = Role::load($rid);
$this->assertEqual($migrate_test_role_1->id(), $rid);
$this->assertEqual($migrate_test_role_1->getPermissions(), array(0 => 'migrate test role 1 test permission', 'use text format full_html'));
$this->assertEqual(array($rid), $migration->getIdMap()->lookupDestinationId(array(3)));
$rid = 'migrate_test_role_2';
$migrate_test_role_2 = entity_load('user_role', $rid);
$migrate_test_role_2 = Role::load($rid);
$this->assertEqual($migrate_test_role_2->getPermissions(), array(
'migrate test role 2 test permission',
'use PHP for settings',
......@@ -92,7 +93,7 @@ public function testUserRole() {
$this->assertEqual($migrate_test_role_2->id(), $rid);
$this->assertEqual(array($rid), $migration->getIdMap()->lookupDestinationId(array(4)));
$rid = 'migrate_test_role_3_that_is_long';
$migrate_test_role_3 = entity_load('user_role', $rid);
$migrate_test_role_3 = Role::load($rid);
$this->assertEqual($migrate_test_role_3->id(), $rid);
$this->assertEqual(array($rid), $migration->getIdMap()->lookupDestinationId(array(5)));
}
......
......@@ -6,6 +6,7 @@
*/
use Drupal\views\ViewExecutable;
use Drupal\user\Entity\Role;
/**
* Implements hook_views_query_substitutions().
......@@ -31,9 +32,9 @@ function node_views_analyze(ViewExecutable $view) {
// check for no access control
$access = $display->getOption('access');
if (empty($access['type']) || $access['type'] == 'none') {
$anonymous_role = entity_load('user_role', DRUPAL_ANONYMOUS_RID);
$anonymous_role = Role::load(DRUPAL_ANONYMOUS_RID);
$anonymous_has_access = $anonymous_role && $anonymous_role->hasPermission('access content');
$authenticated_role = entity_load('user_role', DRUPAL_AUTHENTICATED_RID);
$authenticated_role = Role::load(DRUPAL_AUTHENTICATED_RID);
$authenticated_has_access = $authenticated_role && $authenticated_role->hasPermission('access content');
if (!$anonymous_has_access || !$authenticated_has_access) {
$ret[] = Analyzer::formatMessage(t('Some roles lack permission to access content, but display %display has no access control.', array('%display' => $display->display['display_title'])), 'warning');
......
......@@ -9,6 +9,7 @@
use Drupal\Core\Entity\EntityInterface;
use Drupal\system\Tests\Entity\EntityWithUriCacheTagsTestBase;
use Drupal\user\Entity\Role;
/**
* Tests the Node entity's cache tags.
......@@ -30,7 +31,7 @@ protected function setUp() {
// Give anonymous users permission to view nodes, so that we can verify the
// cache tags of cached versions of node pages.
$user_role = entity_load('user_role', DRUPAL_ANONYMOUS_RID);
$user_role = Role::load(DRUPAL_ANONYMOUS_RID);
$user_role->grantPermission('acess content');
$user_role->save();
}
......
......@@ -9,6 +9,7 @@
use Drupal\shortcut\Entity\Shortcut;
use Drupal\system\Tests\Entity\EntityCacheTagsTestBase;
use Drupal\user\Entity\Role;
/**
* Tests the Shortcut entity's cache tags.
......@@ -30,7 +31,7 @@ protected function setUp() {
// Give anonymous users permission to customize shortcut links, so that we
// can verify the cache tags of cached versions of shortcuts.
$user_role = entity_load('user_role', DRUPAL_ANONYMOUS_RID);
$user_role = Role::load(DRUPAL_ANONYMOUS_RID);
$user_role->grantPermission('customize shortcut links');
$user_role->grantPermission('access shortcuts');
$user_role->save();
......
......@@ -28,6 +28,7 @@
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\block\Entity\Block;
use Symfony\Component\HttpFoundation\Request;
use Drupal\user\Entity\Role;
/**
* Test case for typical Drupal tests.
......@@ -599,7 +600,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())->getPermissions();
$assigned_permissions = Role::load($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');
......
......@@ -11,6 +11,7 @@
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\system\Tests\Cache\PageCacheTagsTestBase;
use Drupal\user\Entity\Role;
/**
* Provides helper methods for Entity cache tags tests.
......@@ -53,7 +54,7 @@ protected function setUp() {
// Give anonymous users permission to view test entities, so that we can
// verify the cache tags of cached versions of test entity pages.
$user_role = entity_load('user_role', DRUPAL_ANONYMOUS_RID);
$user_role = Role::load(DRUPAL_ANONYMOUS_RID);
$user_role->grantPermission('view test entity');
$user_role->save();
......
......@@ -38,7 +38,7 @@ public function form(array $form, FormStateInterface $form_state) {
'#size' => 30,
'#maxlength' => 64,
'#machine_name' => array(
'exists' => 'user_role_load',
'exists' => ['\Drupal\user\Entity\Role', 'load'],
),
);
$form['weight'] = array(
......
......@@ -8,6 +8,7 @@
namespace Drupal\user\Tests;
use Drupal\system\Tests\Entity\EntityWithUriCacheTagsTestBase;
use Drupal\user\Entity\Role;
/**
* Tests the User entity's cache tags.
......@@ -29,7 +30,7 @@ protected function setUp() {
// Give anonymous users permission to view user profiles, so that we can
// verify the cache tags of cached versions of user profile pages.
$user_role = entity_load('user_role', DRUPAL_ANONYMOUS_RID);
$user_role = Role::load(DRUPAL_ANONYMOUS_RID);
$user_role->grantPermission('access user profiles');
$user_role->save();
}
......
......@@ -8,6 +8,7 @@
namespace Drupal\user\Tests;
use Drupal\simpletest\WebTestBase;
use Drupal\user\Entity\Role;
/**
* Tests adding, editing and deleting user roles and changing role weights.
......@@ -42,7 +43,7 @@ function testRoleAdministration() {
$edit = array('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)));
$role = entity_load('user_role', $role_name);
$role = Role::load($role_name);
$this->assertTrue(is_object($role), 'The role was successfully retrieved from the database.');
// Check that the role was created in site default language.
......@@ -57,7 +58,8 @@ function testRoleAdministration() {
$edit = array('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)));
$new_role = entity_load('user_role', $role->id(), TRUE);
\Drupal::entityManager()->getStorage('user_role')->resetCache(array($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.
......@@ -66,7 +68,8 @@ function testRoleAdministration() {
$this->drupalPostForm(NULL, array(), t('Delete'));
$this->assertRaw(t('Role %label has been deleted.', array('%label' => $role_name)));
$this->assertNoLinkByHref("admin/people/roles/manage/{$role->id()}", 'Role edit link removed.');
$this->assertFalse(entity_load('user_role', $role->id(), TRUE), 'A deleted role can no longer be loaded.');
\Drupal::entityManager()->getStorage('user_role')->resetCache(array($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
// interface.
......
......@@ -387,7 +387,7 @@ function user_role_permissions(array $roles) {
if (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'update') {
return _user_role_permissions_update($roles);
}
$entities = entity_load_multiple('user_role', $roles);
$entities = Role::loadMultiple($roles);
$role_permissions = array();
foreach ($roles as $rid) {
$role_permissions[$rid] = isset($entities[$rid]) ? $entities[$rid]->getPermissions() : array();
......@@ -1155,7 +1155,7 @@ function user_roles($membersonly = FALSE, $permission = NULL) {
}
}
$roles = entity_load_multiple('user_role');
$roles = Role::loadMultiple();
if ($membersonly) {
unset($roles[DRUPAL_ANONYMOUS_RID]);
}
......@@ -1245,7 +1245,7 @@ function user_role_change_permissions($rid, array $permissions = array()) {
*/
function user_role_grant_permissions($rid, array $permissions = array()) {
// Grant new permissions for the role.
$role = entity_load('user_role', $rid);
$role = Role::load($rid);
foreach ($permissions as $permission) {
$role->grantPermission($permission);
}
......@@ -1265,7 +1265,7 @@ function user_role_grant_permissions($rid, array $permissions = array()) {
*/
function user_role_revoke_permissions($rid, array $permissions = array()) {
// Revoke permissions for the role.
$role = entity_load('user_role', $rid);
$role = Role::load($rid);
foreach ($permissions as $permission) {
$role->revokePermission($permission);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment