diff --git a/core/modules/aggregator/src/Tests/FeedCacheTagsTest.php b/core/modules/aggregator/src/Tests/FeedCacheTagsTest.php index fbe452413b0b..2ad5f5a5eda0 100644 --- a/core/modules/aggregator/src/Tests/FeedCacheTagsTest.php +++ b/core/modules/aggregator/src/Tests/FeedCacheTagsTest.php @@ -9,6 +9,7 @@ namespace Drupal\aggregator\Tests; 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 @@ class FeedCacheTagsTest extends EntityWithUriCacheTagsTestBase { // 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(); } diff --git a/core/modules/aggregator/src/Tests/ItemCacheTagsTest.php b/core/modules/aggregator/src/Tests/ItemCacheTagsTest.php index 12b893c6bcac..3a80ebe36d1e 100644 --- a/core/modules/aggregator/src/Tests/ItemCacheTagsTest.php +++ b/core/modules/aggregator/src/Tests/ItemCacheTagsTest.php @@ -10,6 +10,7 @@ namespace Drupal\aggregator\Tests; 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 @@ class ItemCacheTagsTest extends EntityCacheTagsTestBase { // 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(); } diff --git a/core/modules/comment/src/Tests/CommentCacheTagsTest.php b/core/modules/comment/src/Tests/CommentCacheTagsTest.php index 921f6ca1a52a..5da555518921 100644 --- a/core/modules/comment/src/Tests/CommentCacheTagsTest.php +++ b/core/modules/comment/src/Tests/CommentCacheTagsTest.php @@ -11,6 +11,7 @@ use Drupal\comment\CommentManagerInterface; 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 @@ class CommentCacheTagsTest extends EntityWithUriCacheTagsTestBase { // 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(); } diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateUserRoleTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateUserRoleTest.php index ee73c6665504..ec087663d1bb 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateUserRoleTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateUserRoleTest.php @@ -9,6 +9,7 @@ namespace Drupal\migrate_drupal\Tests\d6; 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 @@ class MigrateUserRoleTest extends MigrateDrupalTestBase { /** @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 @@ class MigrateUserRoleTest extends MigrateDrupalTestBase { $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))); } diff --git a/core/modules/node/node.views_execution.inc b/core/modules/node/node.views_execution.inc index f97b8adeccb5..4f162f4d78ef 100644 --- a/core/modules/node/node.views_execution.inc +++ b/core/modules/node/node.views_execution.inc @@ -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'); diff --git a/core/modules/node/src/Tests/NodeCacheTagsTest.php b/core/modules/node/src/Tests/NodeCacheTagsTest.php index 881ae546aa01..b85d17568d30 100644 --- a/core/modules/node/src/Tests/NodeCacheTagsTest.php +++ b/core/modules/node/src/Tests/NodeCacheTagsTest.php @@ -9,6 +9,7 @@ namespace Drupal\node\Tests; 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 @@ class NodeCacheTagsTest extends EntityWithUriCacheTagsTestBase { // 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(); } diff --git a/core/modules/shortcut/src/Tests/ShortcutCacheTagsTest.php b/core/modules/shortcut/src/Tests/ShortcutCacheTagsTest.php index 836cf4f2467a..98b0904b45f8 100644 --- a/core/modules/shortcut/src/Tests/ShortcutCacheTagsTest.php +++ b/core/modules/shortcut/src/Tests/ShortcutCacheTagsTest.php @@ -9,6 +9,7 @@ namespace Drupal\shortcut\Tests; 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 @@ class ShortcutCacheTagsTest extends EntityCacheTagsTestBase { // 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(); diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php index 3c826bfee32a..98f68fcc84a0 100644 --- a/core/modules/simpletest/src/WebTestBase.php +++ b/core/modules/simpletest/src/WebTestBase.php @@ -28,6 +28,7 @@ use Drupal\Core\StreamWrapper\PublicStream; 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 @@ 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())->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'); diff --git a/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php b/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php index 3c981c12ab4b..f0185398bd68 100644 --- a/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php +++ b/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php @@ -11,6 +11,7 @@ use Drupal\Core\Cache\Cache; 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 @@ abstract class EntityCacheTagsTestBase extends PageCacheTagsTestBase { // 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(); diff --git a/core/modules/user/src/RoleForm.php b/core/modules/user/src/RoleForm.php index d9ef7cda7591..b05c164eaf96 100644 --- a/core/modules/user/src/RoleForm.php +++ b/core/modules/user/src/RoleForm.php @@ -38,7 +38,7 @@ class RoleForm extends EntityForm { '#size' => 30, '#maxlength' => 64, '#machine_name' => array( - 'exists' => 'user_role_load', + 'exists' => ['\Drupal\user\Entity\Role', 'load'], ), ); $form['weight'] = array( diff --git a/core/modules/user/src/Tests/UserCacheTagsTest.php b/core/modules/user/src/Tests/UserCacheTagsTest.php index 4085de4f3f52..2fa9baf1fa08 100644 --- a/core/modules/user/src/Tests/UserCacheTagsTest.php +++ b/core/modules/user/src/Tests/UserCacheTagsTest.php @@ -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 @@ class UserCacheTagsTest extends EntityWithUriCacheTagsTestBase { // 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(); } diff --git a/core/modules/user/src/Tests/UserRoleAdminTest.php b/core/modules/user/src/Tests/UserRoleAdminTest.php index e8e8815f8358..7d18b0a2ed7c 100644 --- a/core/modules/user/src/Tests/UserRoleAdminTest.php +++ b/core/modules/user/src/Tests/UserRoleAdminTest.php @@ -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 @@ class UserRoleAdminTest extends WebTestBase { $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 @@ class UserRoleAdminTest extends WebTestBase { $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 @@ class UserRoleAdminTest extends WebTestBase { $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. diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 82aca31730ad..f2ecb69333ee 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -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); }