Commit db27d795 authored by xjm's avatar xjm
Browse files

Issue #2322195 by rpayanm, nlisgo, cilefen, balagan, LinL, akashjain132,...

Issue #2322195 by rpayanm, nlisgo, cilefen, balagan, LinL, akashjain132, filijonka, epari.siva, Tebro, Temoor, pcambra, unstatu, Poornima3, Shivam Agarwal, abhi170893, Dom., PieterJanPut, Mile23, JeroenT, disasm: Replace all instances of user_load(), user_load_multiple(), entity_load('user') and entity_load_multiple('user') with static method calls
parent d0ac1056
......@@ -26,7 +26,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Route;
use Drupal\user\Entity\User;
use GuzzleHttp\Exception\RequestException;
/**
......@@ -1851,7 +1851,7 @@ function install_finished(&$install_state) {
// Load current user and perform final login tasks.
// This has to be done after drupal_flush_all_caches()
// to avoid session regeneration.
$account = user_load(1);
$account = User::load(1);
user_login_finalize($account);
}
......
......@@ -40,7 +40,7 @@
* // Load a node and a user, then replace tokens in the text.
* $text = 'On [date:short], [user:name] read [node:title].';
* $node = Node::load(1);
* $user = user_load(1);
* $user = User::load(1);
*
* // [date:...] tokens use the current date automatically.
* $data = array('node' => $node, 'user' => $user);
......
......@@ -9,6 +9,7 @@
use Drupal\views\Tests\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
use Drupal\user\Entity\User;
/**
* Tests the contact link field.
......@@ -55,7 +56,7 @@ protected function setUp() {
*/
public function testContactLink() {
$accounts = array();
$accounts['root'] = user_load(1);
$accounts['root'] = User::load(1);
// Create an account with access to all contact pages.
$admin_account = $this->drupalCreateUser(array('administer users'));
$accounts['admin'] = $admin_account;
......
......@@ -11,6 +11,7 @@
use Drupal\content_translation\Tests\ContentTranslationTestBase;
use Drupal\views\Tests\ViewTestData;
use Drupal\Core\Language\Language;
use Drupal\user\Entity\User;
/**
* Tests the content translation overview link field handler.
......@@ -41,12 +42,12 @@ protected function setUp() {
parent::setUp();
// Assign user 1 a language code so that the entity can be translated.
$user = user_load(1);
$user = User::load(1);
$user->langcode = 'en';
$user->save();
// Assign user 2 LANGCODE_NOT_SPECIFIED code so entity can't be translated.
$user = user_load(2);
$user = User::load(2);
$user->langcode = Language::LANGCODE_NOT_SPECIFIED;
$user->save();
......
......@@ -53,6 +53,13 @@ class DbLogController extends ControllerBase {
*/
protected $formBuilder;
/**
* The user storage.
*
* @var \Drupal\user\UserStorageInterface
*/
protected $userStorage;
/**
* {@inheritdoc}
*/
......@@ -82,6 +89,7 @@ public function __construct(Connection $database, ModuleHandlerInterface $module
$this->moduleHandler = $module_handler;
$this->dateFormatter = $date_formatter;
$this->formBuilder = $form_builder;
$this->userStorage = $this->entityManager()->getStorage('user');
}
/**
......@@ -188,7 +196,7 @@ public function overview() {
}
$username = array(
'#theme' => 'username',
'#account' => user_load($dblog->uid),
'#account' => $this->userStorage->load($dblog->uid),
);
$rows[] = array(
'data' => array(
......@@ -239,7 +247,7 @@ public function eventDetails($event_id) {
$message = $this->formatMessage($dblog);
$username = array(
'#theme' => 'username',
'#account' => user_load($dblog->uid),
'#account' => $this->userStorage->load($dblog->uid),
);
$rows = array(
array(
......
......@@ -16,6 +16,7 @@
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\taxonomy\Entity\Vocabulary;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
use Drupal\user\Entity\User;
/**
* Implements hook_help().
......@@ -629,7 +630,7 @@ function template_preprocess_forum_icon(&$variables) {
function template_preprocess_forum_submitted(&$variables) {
$variables['author'] = '';
if (isset($variables['topic']->uid)) {
$username = array('#theme' => 'username', '#account' => user_load($variables['topic']->uid));
$username = array('#theme' => 'username', '#account' => User::load($variables['topic']->uid));
$variables['author'] = drupal_render($username);
}
$variables['time'] = isset($variables['topic']->created) ? \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $variables['topic']->created) : '';
......
......@@ -7,6 +7,7 @@
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Language\LanguageInterface;
use Drupal\user\Entity\User;
/**
* Implements hook_token_info().
......@@ -174,7 +175,7 @@ function node_tokens($type, $tokens, array $data = array(), array $options = arr
// Default values for the chained tokens handled below.
case 'author':
$account = $node->getOwner() ? $node->getOwner() : user_load(0);
$account = $node->getOwner() ? $node->getOwner() : User::load(0);
$replacements[$original] = $sanitize ? SafeMarkup::checkPlain($account->label()) : $account->label();
break;
......
......@@ -10,6 +10,7 @@
use Drupal\Core\Language\LanguageInterface;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\node\Entity\NodeType;
use Drupal\user\Entity\User;
/**
* Tests node access functionality with multiple languages and two node access
......@@ -86,7 +87,7 @@ protected function setUp() {
// Load the user 1 user for later use as an admin user with permission to
// see everything.
$this->adminUser = user_load(1);
$this->adminUser = User::load(1);
// The node_access_test_language module allows individual translations of a
// node to be marked private (not viewable by normal users), and the
......
......@@ -9,6 +9,7 @@
use Drupal\Core\Language\LanguageInterface;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\user\Entity\User;
/**
* Tests node_access and db_select() with node_access tag functionality with
......@@ -79,7 +80,7 @@ protected function setUp() {
// Load the user 1 user for later use as an admin user with permission to
// see everything.
$this->adminUser = user_load(1);
$this->adminUser = User::load(1);
// Add Hungarian and Catalan.
ConfigurableLanguage::createFromLangcode('hu')->save();
......
......@@ -10,6 +10,7 @@
use Drupal\Core\Language\LanguageInterface;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\node\Entity\NodeType;
use Drupal\user\Entity\User;
/**
* Tests node_access and db_select() with node_access tag functionality with
......@@ -226,7 +227,7 @@ function testNodeAccessQueryTag() {
// Load the user 1 user for later use as an admin user with permission to
// see everything.
$admin_user = user_load(1);
$admin_user = User::load(1);
// Creating a private node with langcode Hungarian, will be saved as
// the fallback in node access table.
......
......@@ -8,7 +8,6 @@
namespace Drupal\rest\Tests;
use Drupal\Core\Url;
use Drupal\rest\Tests\RESTTestBase;
/**
* Tests the deletion of resources.
......@@ -72,7 +71,9 @@ public function testDelete() {
$account = $this->drupalCreateUser();
$this->drupalLogin($account);
$this->httpRequest($account->urlInfo(), 'DELETE');
$user = entity_load('user', $account->id(), TRUE);
$user_storage = $this->container->get('entity.manager')->getStorage('user');
$user_storage->resetCache(array($account->id()));
$user = $user_storage->load($account->id());
$this->assertEqual($account->id(), $user->id(), 'User still exists in the database.');
$this->assertResponse(405);
}
......
......@@ -678,7 +678,7 @@ protected function checkPermissions(array $permissions) {
* $this->drupalLogin($account);
* // Load real user object.
* $pass_raw = $account->passRaw;
* $account = user_load($account->id());
* $account = User::load($account->id());
* $account->passRaw = $pass_raw;
* @endcode
*
......
......@@ -672,7 +672,7 @@ protected function checkPermissions(array $permissions) {
* $this->drupalLogin($account);
* // Load real user object.
* $pass_raw = $account->pass_raw;
* $account = user_load($account->id());
* $account = User::load($account->id());
* $account->pass_raw = $pass_raw;
* @endcode
*
......
......@@ -16,6 +16,7 @@
use Drupal\taxonomy\Entity\Term;
use Drupal\node\Entity\Node;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\user\Entity\User;
/**
* Tests the invocation of hooks when creating, inserting, loading, updating or
......@@ -504,7 +505,7 @@ public function testUserHooks() {
));
$GLOBALS['entity_crud_hook_test'] = array();
user_load($account->id());
User::load($account->id());
$this->assertHookMessageOrder(array(
'entity_crud_hook_test_entity_load called for type user',
......
......@@ -12,6 +12,7 @@
use Drupal\Core\Language\LanguageInterface;
use Drupal\comment\CommentInterface;
use Drupal\simpletest\WebTestBase;
use Drupal\user\Entity\User;
/**
* Tests for the base handlers provided by Entity Reference.
......@@ -209,8 +210,8 @@ public function testUserHandler() {
// Build a set of test data.
$user_values = array(
'anonymous' => user_load(0),
'admin' => user_load(1),
'anonymous' => User::load(0),
'admin' => User::load(1),
'non_admin' => array(
'name' => 'non_admin <&>',
'mail' => 'non_admin@example.com',
......
......@@ -10,6 +10,7 @@
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\user\Entity\User;
/**
* Form controller for database_test module.
......@@ -53,7 +54,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$options = array();
foreach (user_load_multiple($uids) as $account) {
foreach (User::loadMultiple($uids) as $account) {
$options[$account->id()] = array(
'title' => array('data' => array('#title' => SafeMarkup::checkPlain($account->getUsername()))),
'username' => SafeMarkup::checkPlain($account->getUsername()),
......
......@@ -10,6 +10,7 @@
use Drupal\Core\PathProcessor\InboundPathProcessorInterface;
use Drupal\Core\PathProcessor\OutboundPathProcessorInterface;
use Symfony\Component\HttpFoundation\Request;
use Drupal\user\Entity\User;
/**
* Path processor for url_alter_test.
......@@ -45,7 +46,7 @@ public function processInbound($path, Request $request) {
public function processOutbound($path, &$options = array(), Request $request = NULL) {
// Rewrite user/uid to user/username.
if (preg_match('!^user/([0-9]+)(/.*)?!', $path, $matches)) {
if ($account = user_load($matches[1])) {
if ($account = User::load($matches[1])) {
$matches += array(2 => '');
$path = 'user/' . $account->getUsername() . $matches[2];
}
......
......@@ -6,6 +6,7 @@
*/
use Drupal\Component\Utility\SafeMarkup;
use Drupal\user\Entity\User;
/**
* @addtogroup hooks
......@@ -84,7 +85,7 @@ function hook_tokens($type, $tokens, array $data = array(), array $options = arr
// Default values for the chained tokens handled below.
case 'author':
$account = $node->getOwner() ? $node->getOwner() : user_load(0);
$account = $node->getOwner() ? $node->getOwner() : User::load(0);
$replacements[$original] = $sanitize ? SafeMarkup::checkPlain($account->label()) : $account->label();
break;
......
......@@ -37,6 +37,13 @@ class UserSelection extends SelectionBase {
*/
protected $connection;
/**
* The user storage.
*
* @var \Drupal\user\UserStorageInterface
*/
protected $userStorage;
/**
* Constructs a new UserSelection object.
*
......@@ -59,6 +66,7 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_manager, $module_handler, $current_user);
$this->connection = $connection;
$this->userStorage = $entity_manager->getStorage('user');
}
/**
......@@ -194,7 +202,7 @@ public function entityQueryAlter(SelectInterface $query) {
$value_part->condition('anonymous_name', $condition['value'], $condition['operator']);
$value_part->compile($this->connection, $query);
$or->condition(db_and()
->where(str_replace('anonymous_name', ':anonymous_name', (string) $value_part), $value_part->arguments() + array(':anonymous_name' => user_format_name(user_load(0))))
->where(str_replace('anonymous_name', ':anonymous_name', (string) $value_part), $value_part->arguments() + array(':anonymous_name' => user_format_name($this->userStorage->load(0))))
->condition('base_table.uid', 0)
);
$query->condition($or);
......
......@@ -8,6 +8,7 @@
namespace Drupal\user\Tests;
use Drupal\simpletest\WebTestBase;
use Drupal\user\Entity\User;
/**
* Tests the user admin listing if views is not enabled.
......@@ -57,7 +58,7 @@ public function testUserListing() {
$admin_user = $this->drupalCreateUser(array('administer users'));
$accounts[$admin_user->label()] = $admin_user;
$accounts['admin'] = entity_load('user', 1);
$accounts['admin'] = User::load(1);
$this->drupalLogin($admin_user);
......
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