diff --git a/core/core.services.yml b/core/core.services.yml index 0ea69d49f367a952bdc7415a29de0402c6e4256a..4d2a29a9b47091bbfedb6260cfe88dc8c327e4f3 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -407,7 +407,7 @@ services: class: Drupal\Core\Access\CsrfTokenGenerator arguments: ['@private_key'] calls: - - [setRequest, ['@?request']] + - [setCurrentUser, ['@?current_user']] access_manager: class: Drupal\Core\Access\AccessManager arguments: ['@router.route_provider', '@url_generator', '@paramconverter_manager'] diff --git a/core/lib/Drupal/Core/Access/CsrfTokenGenerator.php b/core/lib/Drupal/Core/Access/CsrfTokenGenerator.php index 910a77b3154ada629487c78f0d5b5fe2c11a6cd8..b74c05d8b4309a40b84834ac6554244944fb731f 100644 --- a/core/lib/Drupal/Core/Access/CsrfTokenGenerator.php +++ b/core/lib/Drupal/Core/Access/CsrfTokenGenerator.php @@ -9,7 +9,7 @@ use Drupal\Component\Utility\Crypt; use Drupal\Core\PrivateKey; -use Symfony\Component\HttpFoundation\Request; +use Drupal\Core\Session\AccountInterface; /** * Generates and validates CSRF tokens. @@ -26,11 +26,11 @@ class CsrfTokenGenerator { protected $privateKey; /** - * The current request object. + * The current user. * - * @var \Symfony\Component\HttpFoundation\Request + * @var \Drupal\Core\Session\AccountInterface */ - protected $request; + protected $currentUser; /** * Constructs the token generator. @@ -43,13 +43,13 @@ public function __construct(PrivateKey $private_key) { } /** - * Sets the $request property. + * Sets the current user. * - * @param \Symfony\Component\HttpFoundation\Request $request - * The HttpRequest object representing the current request. + * @param \Drupal\Core\Session\AccountInterface|null $current_user + * The current user service. */ - public function setRequest(Request $request) { - $this->request = $request; + public function setCurrentUser(AccountInterface $current_user = NULL) { + $this->currentUser = $current_user; } /** @@ -84,9 +84,7 @@ public function get($value = '') { * is TRUE, the return value will always be TRUE for anonymous users. */ public function validate($token, $value = '', $skip_anonymous = FALSE) { - $user = $this->request->attributes->get('_account'); - - return ($skip_anonymous && $user->isAnonymous()) || ($token == $this->get($value)); + return ($skip_anonymous && $this->currentUser->isAnonymous()) || ($token == $this->get($value)); } } diff --git a/core/lib/Drupal/Core/Authentication/AuthenticationManager.php b/core/lib/Drupal/Core/Authentication/AuthenticationManager.php index f66941084a5e31f9f7a138322751067ff7d4de9d..d3630c42d523d195b6bf7fbdde924d012ea19b07 100644 --- a/core/lib/Drupal/Core/Authentication/AuthenticationManager.php +++ b/core/lib/Drupal/Core/Authentication/AuthenticationManager.php @@ -110,7 +110,6 @@ public function authenticate(Request $request) { // Save the authenticated account and the provider that supplied it // for later access. - $request->attributes->set('_account', $account); $request->attributes->set('_authentication_provider', $this->triggeredProviderId); // The global $user object is included for backward compatibility only and diff --git a/core/lib/Drupal/Core/EventSubscriber/SpecialAttributesRouteSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/SpecialAttributesRouteSubscriber.php index 39f9cebd0f655fa11772ee3e9c5719ddd00d3659..3bd54a18c801b3d52dd6f0ce9bfb74017fbf9b38 100644 --- a/core/lib/Drupal/Core/EventSubscriber/SpecialAttributesRouteSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/SpecialAttributesRouteSubscriber.php @@ -23,7 +23,6 @@ class SpecialAttributesRouteSubscriber extends RouteSubscriberBase { */ protected function alterRoutes(RouteCollection $collection, $module) { $special_variables = array( - '_account', 'system_path', '_maintenance', '_legacy', diff --git a/core/lib/Drupal/Core/Form/FormBase.php b/core/lib/Drupal/Core/Form/FormBase.php index 2fad298bad642a2a101a546a8c63da0630dab902..42ec8befc81cf3f6dd34b0fb0cc8c7f0370ce125 100644 --- a/core/lib/Drupal/Core/Form/FormBase.php +++ b/core/lib/Drupal/Core/Form/FormBase.php @@ -178,7 +178,7 @@ public function setRequest(Request $request) { * The current user. */ protected function currentUser() { - return $this->getRequest()->attributes->get('_account'); + return \Drupal::currentUser(); } /** diff --git a/core/lib/Drupal/Core/Routing/Enhancer/AuthenticationEnhancer.php b/core/lib/Drupal/Core/Routing/Enhancer/AuthenticationEnhancer.php index 70124126509629e9f943c1d1c14ded993f8bcbbc..6e577b92f12037a8697f536ef7fa3fd8059c05cf 100644 --- a/core/lib/Drupal/Core/Routing/Enhancer/AuthenticationEnhancer.php +++ b/core/lib/Drupal/Core/Routing/Enhancer/AuthenticationEnhancer.php @@ -55,8 +55,6 @@ public function enhance(array $defaults, Request $request) { $anonymous_user = drupal_anonymous_user(); $this->container->set('current_user', $anonymous_user, 'request'); - // @todo Remove this in https://drupal.org/node/2073531 - $request->attributes->set('_account', $anonymous_user); // The global $user object is included for backward compatibility only // and should be considered deprecated. diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index f6ab885ae26191ce288c83e9ae000deaa32c0ab8..9f8b2827a2b608d1e63f896cb4d8db9388ac9c08 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -1175,9 +1175,7 @@ function comment_load($cid, $reset = FALSE) { * The number of new comments or FALSE if the user is not logged in. */ function comment_num_new($entity_id, $entity_type, $field_name = NULL, $timestamp = 0) { - global $user; - - if ($user->isAuthenticated() && \Drupal::moduleHandler()->moduleExists('history')) { + if (\Drupal::currentUser()->isAuthenticated() && \Drupal::moduleHandler()->moduleExists('history')) { // Retrieve the timestamp at which the current user last viewed this entity. if (!$timestamp) { if ($entity_type == 'node') { diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentNodeAccessTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentNodeAccessTest.php index 652e7fa9f3fa70f0fcf9c60e5d73b6655b0dc0e7..0b8936da8468aa6fd8173888a991af70b854c5ad 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentNodeAccessTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentNodeAccessTest.php @@ -46,6 +46,9 @@ function setUp() { 'node test view', 'skip comment approval', )); + + // Set the author of the created node to the web_user uid. + $this->node->setAuthorId($this->web_user->id())->save(); } /** diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php index a90be4a7f9b56960a4c6165c87ae9fa00336835c..e9fd5753498b70d2958804aaff7f4dd340c80481 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php @@ -155,7 +155,7 @@ protected function assertPublishedStatus() { * Tests translate link on comment content admin page. */ function testTranslateLinkCommentAdminPage() { - $this->admin_user = $this->drupalCreateUser(array_merge(parent::getTranslatorPermissions(), array('access administration pages', 'administer comments'))); + $this->admin_user = $this->drupalCreateUser(array_merge(parent::getTranslatorPermissions(), array('access administration pages', 'administer comments', 'skip comment approval'))); $this->drupalLogin($this->admin_user); $cid_translatable = $this->createEntity(array(), $this->langcodes[0]); diff --git a/core/modules/comment/lib/Drupal/comment/Tests/Views/CommentTestBase.php b/core/modules/comment/lib/Drupal/comment/Tests/Views/CommentTestBase.php index 269d2c57906c5d53f378e638c8aa356151c0b1af..83e34aa10c832f6c553c9caf288c861ac46283e7 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/Views/CommentTestBase.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/Views/CommentTestBase.php @@ -36,7 +36,7 @@ function setUp() { // Add two users, create a node with the user1 as author and another node // with user2 as author. For the second node add a comment from user1. - $this->account = $this->drupalCreateUser(); + $this->account = $this->drupalCreateUser(array('skip comment approval')); $this->account2 = $this->drupalCreateUser(); $this->drupalLogin($this->account); diff --git a/core/modules/content_translation/lib/Drupal/content_translation/ContentTranslationController.php b/core/modules/content_translation/lib/Drupal/content_translation/ContentTranslationController.php index a639f30f7188a519b614d91a8aeced6bc64c30c7..634043ba8197c832544ee79b9056cfc24226276a 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/ContentTranslationController.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/ContentTranslationController.php @@ -234,7 +234,14 @@ public function entityFormAlter(array &$form, array &$form_state, EntityInterfac ); } - $name = $new_translation ? $GLOBALS['user']->getUsername() : user_load($entity->translation[$form_langcode]['uid'])->getUsername(); + // Default to the anonymous user. + $name = ''; + if ($new_translation) { + $name = $GLOBALS['user']->getUsername(); + } + elseif ($entity->translation[$form_langcode]['uid']) { + $name = user_load($entity->translation[$form_langcode]['uid'])->getUsername(); + } $form['content_translation']['name'] = array( '#type' => 'textfield', '#title' => t('Authored by'), diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php index b60198b79fc9908d8bb47336b2598deba2d60019..98373ae2b9aef7e442222d512672416feff66bec 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php @@ -119,8 +119,7 @@ public function testNodeHandler() { // Test as a non-admin. $normal_user = $this->drupalCreateUser(array('access content')); - $request = $this->container->get('request'); - $request->attributes->set('_account', $normal_user); + $this->container->set('current_user', $normal_user); $referenceable_tests = array( array( 'arguments' => array( @@ -172,7 +171,7 @@ public function testNodeHandler() { // Test as an admin. $admin_user = $this->drupalCreateUser(array('access content', 'bypass node access')); - $request->attributes->set('_account', $admin_user); + $this->container->set('current_user', $admin_user); $referenceable_tests = array( array( 'arguments' => array( @@ -266,8 +265,7 @@ public function testUserHandler() { } // Test as a non-admin. - $request = $this->container->get('request'); - $request->attributes->set('_account', $users['non_admin']); + $this->container->set('current_user', $users['non_admin']); $referenceable_tests = array( array( 'arguments' => array( @@ -306,7 +304,7 @@ public function testUserHandler() { ); $this->assertReferenceable($instance, $referenceable_tests, 'User handler'); - $request->attributes->set('_account', $users['admin']); + $this->container->set('current_user', $users['admin']); $referenceable_tests = array( array( 'arguments' => array( @@ -448,8 +446,7 @@ public function testCommentHandler() { // Test as a non-admin. $normal_user = $this->drupalCreateUser(array('access content', 'access comments')); - $request = $this->container->get('request'); - $request->attributes->set('_account', $normal_user); + $this->container->set('current_user', $normal_user); $referenceable_tests = array( array( 'arguments' => array( @@ -488,7 +485,7 @@ public function testCommentHandler() { // Test as a comment admin. $admin_user = $this->drupalCreateUser(array('access content', 'access comments', 'administer comments')); - $request->attributes->set('_account', $admin_user); + $this->container->set('current_user', $admin_user); $referenceable_tests = array( array( 'arguments' => array( @@ -506,7 +503,7 @@ public function testCommentHandler() { // Test as a node and comment admin. $admin_user = $this->drupalCreateUser(array('access content', 'access comments', 'administer comments', 'bypass node access')); - $request->attributes->set('_account', $admin_user); + $this->container->set('current_user', $admin_user); $referenceable_tests = array( array( 'arguments' => array( diff --git a/core/modules/filter/filter.module b/core/modules/filter/filter.module index ba0df51fc5462afa4a8af5db76f8b42fc7b2e5aa..10416062002b7b13f02d2da407228224fe30ad6a 100644 --- a/core/modules/filter/filter.module +++ b/core/modules/filter/filter.module @@ -303,9 +303,8 @@ function filter_get_formats_by_role($rid) { * @see filter_fallback_format() */ function filter_default_format(AccountInterface $account = NULL) { - global $user; if (!isset($account)) { - $account = $user; + $account = \Drupal::currentUser(); } // Get a list of formats for this user, ordered by weight. The first one // available is the user's default format. diff --git a/core/modules/forum/lib/Drupal/forum/Tests/Views/ForumIntegrationTest.php b/core/modules/forum/lib/Drupal/forum/Tests/Views/ForumIntegrationTest.php index 3dbde9fc1ae59351bbd66a28b8b63165dae2ccdf..b7fe19da10188cc9fd109747776327585556ccf9 100644 --- a/core/modules/forum/lib/Drupal/forum/Tests/Views/ForumIntegrationTest.php +++ b/core/modules/forum/lib/Drupal/forum/Tests/Views/ForumIntegrationTest.php @@ -62,6 +62,9 @@ public function testForumIntegration() { $nodes[] = $node; } + $account = $this->drupalCreateUser(array('skip comment approval')); + $this->drupalLogin($account); + $comments = array(); foreach ($nodes as $index => $node) { for ($i = 0; $i <= $index; $i++) { diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeAccessPagerTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeAccessPagerTest.php index 020ced209ef5d49f87ccf3ec3c780b612827651c..579626a9a1f5e85ba08e4333d585674c504f41d7 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeAccessPagerTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeAccessPagerTest.php @@ -55,6 +55,7 @@ public function testCommentPager() { 'comment_body' => array( array('value' => $this->randomName()), ), + 'status' => COMMENT_PUBLISHED, )); $comment->save(); } diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 438104d4822a17054f87ad73d343a61f07429fcf..79c7b4455a232b886547e4aedfb37118097a2d2d 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -1735,11 +1735,9 @@ function node_access_view_all_nodes($account = NULL) { * @endcode */ function node_query_node_access_alter(AlterableInterface $query) { - global $user; - // Read meta-data from query, if provided. if (!$account = $query->getMetaData('account')) { - $account = $user; + $account = \Drupal::currentUser(); } if (!$op = $query->getMetaData('op')) { $op = 'view'; diff --git a/core/modules/search/lib/Drupal/search/Plugin/SearchInterface.php b/core/modules/search/lib/Drupal/search/Plugin/SearchInterface.php index 21478fe5b68b6b7bae362d23a88615a934568b4d..c4738387de7db79328a5a55e7a98abbb88933875 100644 --- a/core/modules/search/lib/Drupal/search/Plugin/SearchInterface.php +++ b/core/modules/search/lib/Drupal/search/Plugin/SearchInterface.php @@ -23,9 +23,7 @@ interface SearchInterface extends PluginInspectionInterface { * Array of parameters as am associative array. This is expected to * be the query string from the current request. * @param array $attributes - * Array of attributes, usually from the current request object. The search - * plugin may use the '_account' attribute if present to personalize the - * search, or use attributes from the current route variables. + * Array of attributes, usually from the current request object. * * @return \Drupal\search\Plugin\SearchInterface * A search plugin object for chaining. diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchCommentCountToggleTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchCommentCountToggleTest.php index 573676f3fa26a8c0a032fb2424c6b78422d6a58d..cb07d81ce279fea5f2b969ca0ca7c153bd42ee08 100644 --- a/core/modules/search/lib/Drupal/search/Tests/SearchCommentCountToggleTest.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchCommentCountToggleTest.php @@ -46,6 +46,9 @@ function setUp() { // Create searching user. $this->searching_user = $this->drupalCreateUser(array('search content', 'access content', 'access comments', 'skip comment approval')); + // Login with sufficient privileges. + $this->drupalLogin($this->searching_user); + // Add a comment field. $this->container->get('comment.manager')->addDefaultField('node', 'article'); // Create initial nodes. @@ -54,9 +57,6 @@ function setUp() { $this->searchable_nodes['1 comment'] = $this->drupalCreateNode($node_params); $this->searchable_nodes['0 comments'] = $this->drupalCreateNode($node_params); - // Login with sufficient privileges. - $this->drupalLogin($this->searching_user); - // Create a comment array $edit_comment = array(); $edit_comment['subject'] = $this->randomName(); diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php index d0edfec386623103d93db3a4f3380808ae9c13e6..c00f72f36b9c409157f7e30a7e74004d50f37ff8 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php @@ -1041,7 +1041,7 @@ protected function rebuildContainer() { // different object, so we need to replace the instance on this test class. $this->container = \Drupal::getContainer(); // The global $user is set in TestBase::prepareEnvironment(). - $this->container->get('request')->attributes->set('_account', $GLOBALS['user']); + $this->container->set('current_user', $GLOBALS['user']); } /** diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index a4c7b273cd5583fdb16df14e3cc896cd6117f73e..e4182843de9a474fbf7a3814d350451665a12ef7 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -277,7 +277,7 @@ protected function drupalCreateNode(array $settings = array()) { $settings['uid'] = $this->loggedInUser->id(); } else { - global $user; + $user = \Drupal::currentUser() ?: $GLOBALS['user']; $settings['uid'] = $user->id(); } } diff --git a/core/modules/system/tests/modules/router_test_directory/lib/Drupal/router_test/TestContent.php b/core/modules/system/tests/modules/router_test_directory/lib/Drupal/router_test/TestContent.php index a4ed1ec2e2ae8e013cecc835491f428939377b47..71d095ccec8b0366c73abb11f4cac183499cc2d8 100644 --- a/core/modules/system/tests/modules/router_test_directory/lib/Drupal/router_test/TestContent.php +++ b/core/modules/system/tests/modules/router_test_directory/lib/Drupal/router_test/TestContent.php @@ -55,7 +55,7 @@ public function test1() { * The user name of the current logged in user. */ public function test11() { - $account = \Drupal::request()->attributes->get('_account'); + $account = \Drupal::currentUser(); return $account->getUsername(); } diff --git a/core/modules/user/lib/Drupal/user/Plugin/Search/UserSearch.php b/core/modules/user/lib/Drupal/user/Plugin/Search/UserSearch.php index 8e5b33615334419dd49274fd6e07f1af6a576486..3921dcbb06746be1e558a197b118f0b7e48be4d6 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/Search/UserSearch.php +++ b/core/modules/user/lib/Drupal/user/Plugin/Search/UserSearch.php @@ -51,11 +51,11 @@ class UserSearch extends SearchPluginBase implements AccessibleInterface { protected $moduleHandler; /** - * The current request. + * The current user. * - * @var \Symfony\Component\HttpFoundation\Request + * @var \Drupal\Core\Session\AccountInterface */ - protected $request; + protected $currentUser; /** * {@inheritdoc} @@ -65,7 +65,7 @@ static public function create(ContainerInterface $container, array $configuratio $container->get('database'), $container->get('plugin.manager.entity'), $container->get('module_handler'), - $container->get('request'), + $container->get('current_user'), $configuration, $plugin_id, $plugin_definition @@ -81,8 +81,8 @@ static public function create(ContainerInterface $container, array $configuratio * The entity manager. * @param ModuleHandlerInterface $module_handler * The module handler. - * @param \Symfony\Component\HttpFoundation\Request $request - * The current request. + * @param \Drupal\Core\Session\AccountInterface $current_user + * The current user. * @param array $configuration * A configuration array containing information about the plugin instance. * @param string $plugin_id @@ -90,11 +90,11 @@ static public function create(ContainerInterface $container, array $configuratio * @param array $plugin_definition * The plugin implementation definition. */ - public function __construct(Connection $database, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler, Request $request, array $configuration, $plugin_id, array $plugin_definition) { + public function __construct(Connection $database, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler, AccountInterface $current_user, array $configuration, $plugin_id, array $plugin_definition) { $this->database = $database; $this->entityManager = $entity_manager; $this->moduleHandler = $module_handler; - $this->request = $request; + $this->currentUser = $current_user; parent::__construct($configuration, $plugin_id, $plugin_definition); } @@ -120,8 +120,7 @@ public function execute() { ->select('users') ->extend('Drupal\Core\Database\Query\PagerSelectExtender'); $query->fields('users', array('uid')); - $user_account = $this->request->attributes->get('_account'); - if ($user_account->hasPermission('administer users')) { + if ($this->currentUser->hasPermission('administer users')) { // Administrators can also search in the otherwise private email field, and // they don't need to be restricted to only active users. $query->fields('users', array('mail')); @@ -147,7 +146,7 @@ public function execute() { 'title' => $account->getUsername(), 'link' => url('user/' . $account->id(), array('absolute' => TRUE)), ); - if ($user_account->hasPermission('administer users')) { + if ($this->currentUser->hasPermission('administer users')) { $result['title'] .= ' (' . $account->getEmail() . ')'; } $results[] = $result; diff --git a/core/modules/user/lib/Drupal/user/Tests/Views/HandlerFieldUserNameTest.php b/core/modules/user/lib/Drupal/user/Tests/Views/HandlerFieldUserNameTest.php index 99659a7a1ffd50c3f382f3862a0bd255f26036ac..1ec2c8bdd550e01f3787ef932b28c3a42b5eb852 100644 --- a/core/modules/user/lib/Drupal/user/Tests/Views/HandlerFieldUserNameTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/Views/HandlerFieldUserNameTest.php @@ -30,6 +30,8 @@ public static function getInfo() { } public function testUserName() { + $this->drupalLogin($this->drupalCreateUser(array('access user profiles'))); + $view = views_get_view('test_views_handler_field_user_name'); $this->executeView($view); diff --git a/core/modules/user/user.module b/core/modules/user/user.module index b55cee6cf5b6d50cce8e293368a30ee15d2fc48b..742727d84685cd0948527c0276d9a4d360e3fcb3 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -452,7 +452,7 @@ function user_access($string, AccountInterface $account = NULL) { if (!isset($account)) { // In the installer request session is not set, so we have to fall back // to the global $user. In all other cases the session key is preferred. - $account = \Drupal::request()->attributes->get('_account') ?: $user; + $account = \Drupal::currentUser() ?: $user; } return $account->hasPermission($string); @@ -1265,7 +1265,7 @@ function user_cancel_methods() { 'user_cancel_delete' => array( 'title' => t('Delete the account and its content.'), 'description' => t('Your account will be removed and all account information deleted. All of your content will also be deleted.'), - 'access' => \Drupal::request()->attributes->get('_account')->hasPermission('administer users'), + 'access' => \Drupal::currentUser()->hasPermission('administer users'), ), ); // Allow modules to customize account cancellation methods. diff --git a/core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php b/core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php index aa058bb948da3ff16bf916d642dc6c3d313f42ea..5b823a2a1bc336149697e4520c72955d060fb839 100644 --- a/core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php +++ b/core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php @@ -49,7 +49,6 @@ function setUp() { ->will($this->returnValue($this->key)); $this->generator = new CsrfTokenGenerator($private_key); - $this->generator->setRequest(new Request()); } /** @@ -79,18 +78,14 @@ public function testValidate() { $account->expects($this->once()) ->method('isAnonymous') ->will($this->returnValue(TRUE)); - $request = new Request(); - $request->attributes->set('_account', $account); - $this->generator->setRequest($request); + $this->generator->setCurrentUser($account); $this->assertTrue($this->generator->validate($token, 'foo', TRUE)); $account = $this->getMock('Drupal\Core\Session\AccountInterface'); $account->expects($this->once()) ->method('isAnonymous') ->will($this->returnValue(FALSE)); - $request = new Request(); - $request->attributes->set('_account', $account); - $this->generator->setRequest($request); + $this->generator->setCurrentUser($account); $this->assertFalse($this->generator->validate($token, 'foo', TRUE)); } diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php index f003327d9e042f8fb3ff1093c6532d5c58d67688..0bb50069c3cd80a5ebc1d13d81e881d22a1d4a10 100644 --- a/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php +++ b/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php @@ -53,7 +53,6 @@ protected function setUp() { */ public function providerTestOnRouteBuildingInvalidVariables() { $routes = array(); - $routes[] = array(new Route('/test/{_account}')); $routes[] = array(new Route('/test/{system_path}')); $routes[] = array(new Route('/test/{_maintenance}')); $routes[] = array(new Route('/test/{_legacy}'));