diff --git a/core/includes/common.inc b/core/includes/common.inc index 60f57f2..f19fcd9 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -5894,7 +5894,7 @@ function drupal_render_cid_parts($granularity = NULL) { // resource drag for sites with many users, so when a module is being // equivocal, we favor the less expensive 'PER_ROLE' pattern. if ($granularity & DRUPAL_CACHE_PER_ROLE) { - $cid_parts[] = 'r.' . implode(',', array_keys($user->roles)); + $cid_parts[] = 'r.' . implode(',', $user->roles); } elseif ($granularity & DRUPAL_CACHE_PER_USER) { $cid_parts[] = "u.$user->uid"; diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterFormatAccessTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterFormatAccessTest.php index 969fac0..47896c0 100644 --- a/core/modules/filter/lib/Drupal/filter/Tests/FilterFormatAccessTest.php +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterFormatAccessTest.php @@ -176,9 +176,7 @@ function testFormatPermissions() { */ function testFormatRoles() { // Get the role ID assigned to the regular user. - $roles = $this->web_user->roles; - unset($roles[DRUPAL_AUTHENTICATED_RID]); - $rid = key($roles); + $rid = $this->web_user->roles[0]; // Check that this role appears in the list of roles that have access to an // allowed text format, but does not appear in the list of roles that have diff --git a/core/modules/locale/lib/Drupal/locale/LocaleLookup.php b/core/modules/locale/lib/Drupal/locale/LocaleLookup.php index cc515b4..7f7d272 100644 --- a/core/modules/locale/lib/Drupal/locale/LocaleLookup.php +++ b/core/modules/locale/lib/Drupal/locale/LocaleLookup.php @@ -46,7 +46,7 @@ public function __construct($langcode, $context, $stringStorage) { // Add the current user's role IDs to the cache key, this ensures that, for // example, strings for admin menu items and settings forms are not cached // for anonymous users. - $rids = implode(':', array_keys($GLOBALS['user']->roles)); + $rids = implode(':', $GLOBALS['user']->roles); parent::__construct("locale:$langcode:$context:$rids", 'cache', array('locale' => TRUE)); } diff --git a/core/modules/node/lib/Drupal/node/NodeAccessController.php b/core/modules/node/lib/Drupal/node/NodeAccessController.php index 815c2ab..5934f5c 100644 --- a/core/modules/node/lib/Drupal/node/NodeAccessController.php +++ b/core/modules/node/lib/Drupal/node/NodeAccessController.php @@ -119,7 +119,7 @@ protected function accessGrants(EntityInterface $node, $operation, $langcode = L $query->range(0, 1); $grants = db_or(); - foreach (node_access_grants($operation, $account) as $realm => $gids) { + foreach (node_access_grants($operation, $account instanceof User ? $account->getBCEntity() : $account) as $realm => $gids) { foreach ($gids as $gid) { $grants->condition(db_and() ->condition('gid', $gid) diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchCommentTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchCommentTest.php index 04d78a4..fbfe050 100644 --- a/core/modules/search/lib/Drupal/search/Tests/SearchCommentTest.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchCommentTest.php @@ -125,9 +125,7 @@ function testSearchResultsComment() { function testSearchResultsCommentAccess() { $comment_body = 'Test comment body'; $this->comment_subject = 'Test comment subject'; - $this->admin_role = $this->admin_user->roles; - unset($this->admin_role[DRUPAL_AUTHENTICATED_RID]); - $this->admin_role = key($this->admin_role); + $this->admin_role = $this->admin_user->roles[0]; // Create a node. variable_set('comment_preview_article', DRUPAL_OPTIONAL); diff --git a/core/modules/system/lib/Drupal/system/Tests/Plugin/ContextPluginTest.php b/core/modules/system/lib/Drupal/system/Tests/Plugin/ContextPluginTest.php index 882ae96..7815a8b 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Plugin/ContextPluginTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Plugin/ContextPluginTest.php @@ -99,7 +99,7 @@ function testContext() { // Set an appropriate context value appropriately and check to make sure // its methods work as expected. - $user = entity_create('user', array('name' => $name)); + $user = entity_create('user', array('name' => $name))->getOriginalEntity(); $plugin->setContextValue('user', $user); $this->assertEqual($user->label(), $plugin->getTitle()); diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/FieldUIUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/FieldUIUpgradePathTest.php index f344afb..6f44942 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/FieldUIUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/FieldUIUpgradePathTest.php @@ -63,7 +63,7 @@ function testFieldUIPermissions() { ), ); - $role_permissions = user_role_permissions(array($this->normal_role_id => $this->normal_role_name, $this->admin_role_id => $this->admin_role_name)); + $role_permissions = user_role_permissions(array($this->normal_role_id, $this->admin_role_id)); foreach ($permissions as $old_permission => $new_permissions) { $this->assertFalse(isset($role_permissions[$this->normal_role_id][$old_permission]), format_string('%role_name does not have the old %permission permission', array('%role_name' => $this->normal_role_name, '%permission' => $old_permission))); $this->assertTrue(isset($role_permissions[$this->admin_role_id][$old_permission]), format_string('%role_name still has the old %permission permission', array('%role_name' => $this->admin_role_name, '%permission' => $old_permission))); diff --git a/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php b/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php index f8c585b..16b19c8 100644 --- a/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php +++ b/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php @@ -231,9 +231,7 @@ function _testTextfieldWidgetsFormatted($field_type, $widget_type) { $format = filter_format_load($edit['format']); $format_id = $format->format; $permission = filter_permission_name($format); - $roles = $this->web_user->roles; - unset($roles[DRUPAL_AUTHENTICATED_RID]); - $rid = key($roles); + $rid = $this->web_user->roles[0]; user_role_grant_permissions($rid, array($permission)); $this->drupalLogin($this->web_user); diff --git a/core/modules/user/lib/Drupal/user/UserStorageController.php b/core/modules/user/lib/Drupal/user/UserStorageController.php index fdb7056..c00937a 100644 --- a/core/modules/user/lib/Drupal/user/UserStorageController.php +++ b/core/modules/user/lib/Drupal/user/UserStorageController.php @@ -96,11 +96,6 @@ protected function preSave(EntityInterface $entity) { } } - // Prepare user roles. - if (isset($entity->roles)) { - //$entity->roles = array_filter($entity->roles); - } - // Store account cancellation information. foreach (array('user_cancel_method', 'user_cancel_notify') as $key) { if (isset($entity->{$key})) { diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 54aec69..77cd489 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -2100,12 +2100,11 @@ function user_multiple_role_edit($accounts, $operation, $rid) { $accounts = user_load_multiple($accounts); foreach ($accounts as $account) { // Skip adding the role to the user if they already have it. - if ($account !== FALSE && !isset($account->roles[$rid])) { - $roles = $account->roles + array($rid => $role_name); + if ($account !== FALSE && !array_search($rid, $account->roles)) { // For efficiency manually save the original account before applying // any changes. $account->original = clone $account; - $account->roles = $roles; + $account->roles[count($account->roles)] = $rid; $account->save(); } } @@ -2114,8 +2113,8 @@ function user_multiple_role_edit($accounts, $operation, $rid) { $accounts = user_load_multiple($accounts); foreach ($accounts as $account) { // Skip removing the role from the user if they already don't have it. - if ($account !== FALSE && isset($account->roles[$rid])) { - $roles = array_diff($account->roles, array($rid => $role_name)); + if ($account !== FALSE && $index = array_search($rid, $account->roles)) { + $roles = array_diff($account->roles, array($rid)); // For efficiency manually save the original account before applying // any changes. $account->original = clone $account; diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/cache/CachePluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/cache/CachePluginBase.php index 7df986e..bd317f5 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/cache/CachePluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/cache/CachePluginBase.php @@ -284,7 +284,7 @@ public function generateResultsKey() { } $key_data = array( 'build_info' => $build_info, - 'roles' => array_keys($user->roles), + 'roles' => $user->roles, 'super-user' => $user->uid == 1, // special caching for super user. 'langcode' => language(LANGUAGE_TYPE_INTERFACE)->langcode, 'base_url' => $GLOBALS['base_url'], @@ -312,7 +312,7 @@ public function generateOutputKey() { if (!isset($this->outputKey)) { $key_data = array( 'result' => $this->view->result, - 'roles' => array_keys($user->roles), + 'roles' => $user->roles, 'super-user' => $user->uid == 1, // special caching for super user. 'theme' => $GLOBALS['theme'], 'langcode' => language(LANGUAGE_TYPE_INTERFACE)->langcode, diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/filter/FilterPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/filter/FilterPluginBase.php index e93b0de..5e08550 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/filter/FilterPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/filter/FilterPluginBase.php @@ -1365,7 +1365,7 @@ public function storeExposedInput($input, $status) { // Check if we store exposed value for current user. global $user; $allowed_rids = empty($this->options['expose']['remember_roles']) ? array() : array_filter($this->options['expose']['remember_roles']); - $intersect_rids = array_intersect_key($allowed_rids, $user->roles); + $intersect_rids = array_intersect(array_keys($allowed_rids), $user->roles); if (empty($intersect_rids)) { return; } diff --git a/core/modules/views/views.module b/core/modules/views/views.module index f1cb911..feb3142 100644 --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -753,9 +753,7 @@ function views_check_perm($perm, $account = NULL) { function views_check_roles($rids, $account = NULL) { global $user; $account = isset($account) ? $account : $user; - $roles = array_keys($account->roles); - $roles[] = $account->uid ? DRUPAL_AUTHENTICATED_RID : DRUPAL_ANONYMOUS_RID; - return user_access('access all views', $account) || array_intersect(array_filter($rids), $roles); + return user_access('access all views', $account) || array_intersect(array_filter($rids), $account->roles); } /**