Skip to content
Snippets Groups Projects
Commit 4b0ce935 authored by Angie Byron's avatar Angie Byron
Browse files

Issue #1634280 by EclipseGc, rlmumford: drupal_anonymous_user() should return a User entity.

parent 7da4cad9
No related branches found
No related tags found
No related merge requests found
......@@ -15,6 +15,7 @@
use Drupal\Core\Language\Language;
use Drupal\Core\Lock\DatabaseLockBackend;
use Drupal\Core\Lock\LockBackendInterface;
use Drupal\user\Plugin\Core\Entity\User;
/**
* @file
......@@ -2032,15 +2033,18 @@ function drupal_hash_base64($data) {
/**
* Generates a default anonymous $user object.
*
* @return Object - the user object.
* @return Drupal\user\Plugin\Core\Entity\User
* The user object.
*/
function drupal_anonymous_user() {
$user = new stdClass();
$user->uid = 0;
$user->hostname = ip_address();
$user->roles = array();
$user->roles[DRUPAL_ANONYMOUS_RID] = DRUPAL_ANONYMOUS_RID;
return $user;
$values = array(
'uid' => 0,
'hostname' => ip_address(),
'roles' => array(
DRUPAL_ANONYMOUS_RID => DRUPAL_ANONYMOUS_RID,
),
);
return new User($values, 'user');
}
/**
......
......@@ -2650,8 +2650,6 @@ function _template_preprocess_default_variables() {
'title_prefix' => array(),
'title_suffix' => array(),
'db_is_active' => !defined('MAINTENANCE_MODE'),
// User module overrides these when it is loaded.
'user' => drupal_anonymous_user(),
'is_admin' => FALSE,
'logged_in' => FALSE,
);
......
......@@ -148,7 +148,7 @@ protected function preSave(EntityInterface $comment) {
}
// We test the value with '===' because we need to modify anonymous
// users as well.
if ($comment->uid->target_id === $user->uid && isset($user->name)) {
if ($comment->uid->target_id === $user->uid && $user->uid) {
$comment->name->value = $user->name;
}
// Add the values which aren't passed into the function.
......
......@@ -33,7 +33,7 @@ function setUp() {
parent::setUp();
$this->account = $this->drupalCreateUser();
$this->anonymous = entity_create('user', (array) drupal_anonymous_user());
$this->anonymous = drupal_anonymous_user();
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment