diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 3e3853a..3ed3ac8 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -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 @@ -2046,12 +2047,14 @@ function drupal_get_hash_salt() { * @return Object - 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'); } /** diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 8172073..929a78f 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -2651,7 +2651,7 @@ function _template_preprocess_default_variables() { 'title_suffix' => array(), 'db_is_active' => !defined('MAINTENANCE_MODE'), // User module overrides these when it is loaded. - 'user' => drupal_anonymous_user(), + //'user' => drupal_anonymous_user(), 'is_admin' => FALSE, 'logged_in' => FALSE, ); diff --git a/core/modules/comment/lib/Drupal/comment/CommentStorageController.php b/core/modules/comment/lib/Drupal/comment/CommentStorageController.php index 6851be0..274b37b 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentStorageController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentStorageController.php @@ -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. diff --git a/core/modules/user/lib/Drupal/user/Tests/UserEntityCallbacksTest.php b/core/modules/user/lib/Drupal/user/Tests/UserEntityCallbacksTest.php index a4bfd52..15894ad 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserEntityCallbacksTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserEntityCallbacksTest.php @@ -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(); } /**