summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcatch2013-11-16 21:26:50 (GMT)
committercatch2013-11-16 21:26:50 (GMT)
commit241348d510ae3800039f569ad749b9e0883dc44a (patch)
tree6158bb4270a30c2ed946b493081ea002038379fe
parent7b8e20411889ddead83846c93d4e523f9b5096eb (diff)
Issue #2073531 by tim.plunkett, dawehner, Berdir, catch, plach: Use current user service instead of _account, remove _account from the request object.
-rw-r--r--core/core.services.yml2
-rw-r--r--core/lib/Drupal/Core/Access/CsrfTokenGenerator.php22
-rw-r--r--core/lib/Drupal/Core/Authentication/AuthenticationManager.php1
-rw-r--r--core/lib/Drupal/Core/EventSubscriber/SpecialAttributesRouteSubscriber.php1
-rw-r--r--core/lib/Drupal/Core/Form/FormBase.php2
-rw-r--r--core/lib/Drupal/Core/Routing/Enhancer/AuthenticationEnhancer.php2
-rw-r--r--core/modules/comment/comment.module4
-rw-r--r--core/modules/comment/lib/Drupal/comment/Tests/CommentNodeAccessTest.php3
-rw-r--r--core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php2
-rw-r--r--core/modules/comment/lib/Drupal/comment/Tests/Views/CommentTestBase.php2
-rw-r--r--core/modules/content_translation/lib/Drupal/content_translation/ContentTranslationController.php9
-rw-r--r--core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php17
-rw-r--r--core/modules/filter/filter.module3
-rw-r--r--core/modules/forum/lib/Drupal/forum/Tests/Views/ForumIntegrationTest.php3
-rw-r--r--core/modules/node/lib/Drupal/node/Tests/NodeAccessPagerTest.php1
-rw-r--r--core/modules/node/node.module4
-rw-r--r--core/modules/search/lib/Drupal/search/Plugin/SearchInterface.php4
-rw-r--r--core/modules/search/lib/Drupal/search/Tests/SearchCommentCountToggleTest.php6
-rw-r--r--core/modules/simpletest/lib/Drupal/simpletest/TestBase.php2
-rw-r--r--core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php2
-rw-r--r--core/modules/system/tests/modules/router_test_directory/lib/Drupal/router_test/TestContent.php2
-rw-r--r--core/modules/user/lib/Drupal/user/Plugin/Search/UserSearch.php21
-rw-r--r--core/modules/user/lib/Drupal/user/Tests/Views/HandlerFieldUserNameTest.php2
-rw-r--r--core/modules/user/user.module4
-rw-r--r--core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php9
-rw-r--r--core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php1
26 files changed, 62 insertions, 69 deletions
diff --git a/core/core.services.yml b/core/core.services.yml
index 0ea69d4..4d2a29a 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 910a77b..b74c05d 100644
--- a/core/lib/Drupal/Core/Access/CsrfTokenGenerator.php
+++ b/core/lib/Drupal/Core/Access/CsrfTokenGenerator.php
@@ -9,7 +9,7 @@ namespace Drupal\Core\Access;
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 @@ class CsrfTokenGenerator {
}
/**
- * 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 @@ class CsrfTokenGenerator {
* 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 f669410..d3630c4 100644
--- a/core/lib/Drupal/Core/Authentication/AuthenticationManager.php
+++ b/core/lib/Drupal/Core/Authentication/AuthenticationManager.php
@@ -110,7 +110,6 @@ class AuthenticationManager implements AuthenticationProviderInterface, Authenti
// 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 39f9ceb..3bd54a1 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 2fad298..42ec8be 100644
--- a/core/lib/Drupal/Core/Form/FormBase.php
+++ b/core/lib/Drupal/Core/Form/FormBase.php
@@ -178,7 +178,7 @@ abstract class FormBase extends DependencySerialization implements FormInterface
* 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 7012412..6e577b9 100644
--- a/core/lib/Drupal/Core/Routing/Enhancer/AuthenticationEnhancer.php
+++ b/core/lib/Drupal/Core/Routing/Enhancer/AuthenticationEnhancer.php
@@ -55,8 +55,6 @@ class AuthenticationEnhancer extends ContainerAware implements RouteEnhancerInte
$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 f6ab885..9f8b282 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 652e7fa..0b8936d 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 @@ class CommentNodeAccessTest extends CommentTestBase {
'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 a90be4a..e9fd575 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 @@ class CommentTranslationUITest extends ContentTranslationUITest {
* 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 269d2c5..83e34aa 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 @@ abstract class CommentTestBase extends ViewTestBase {
// 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 a639f30..634043b 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 @@ class ContentTranslationController implements ContentTranslationControllerInterf
);
}
- $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 b60198b..98373ae 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 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
// 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 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
// 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 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
}
// 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 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
);
$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 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
// 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 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
// 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 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
// 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 ba0df51..1041606 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 3dbde9f..b7fe19d 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 @@ class ForumIntegrationTest extends ViewTestBase {
$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 020ced2..579626a 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 @@ class NodeAccessPagerTest extends WebTestBase {
'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 438104d..79c7b44 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 21478fe..c473838 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 573676f..cb07d81 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 @@ class SearchCommentCountToggleTest extends SearchTestBase {
// 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 @@ class SearchCommentCountToggleTest extends SearchTestBase {
$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 d0edfec..c00f72f 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
@@ -1041,7 +1041,7 @@ abstract class TestBase {
// 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 a4c7b27..e418284 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
@@ -277,7 +277,7 @@ abstract class WebTestBase extends TestBase {
$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 a4ed1ec..71d095c 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 @@ class TestContent extends ContainerAware implements ContainerInjectionInterface
* 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 8e5b336..3921dcb 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 @@ class UserSearch extends SearchPluginBase implements AccessibleInterface {
$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 @@ class UserSearch extends SearchPluginBase implements AccessibleInterface {
* 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 @@ class UserSearch extends SearchPluginBase implements AccessibleInterface {
* @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 @@ class UserSearch extends SearchPluginBase implements AccessibleInterface {
->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 @@ class UserSearch extends SearchPluginBase implements AccessibleInterface {
'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 99659a7..1ec2c8b 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 @@ class HandlerFieldUserNameTest extends UserTestBase {
}
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 b55cee6..742727d 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 aa058bb..5b823a2 100644
--- a/core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php
+++ b/core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php
@@ -49,7 +49,6 @@ class CsrfTokenGeneratorTest extends UnitTestCase {
->will($this->returnValue($this->key));
$this->generator = new CsrfTokenGenerator($private_key);
- $this->generator->setRequest(new Request());
}
/**
@@ -79,18 +78,14 @@ class CsrfTokenGeneratorTest extends UnitTestCase {
$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 f003327..0bb5006 100644
--- a/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php
+++ b/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php
@@ -53,7 +53,6 @@ class SpecialAttributesRouteSubscriberTest extends UnitTestCase {
*/
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}'));