You are here

public static function User::getAnonymousUser in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/user/src/Entity/User.php \Drupal\user\Entity\User::getAnonymousUser()

Returns an anonymous user entity.

Return value

\Drupal\user\UserInterface An anonymous user entity.

4 calls to User::getAnonymousUser()
Comment::getOwner in core/modules/comment/src/Entity/Comment.php
Returns the entity owner's user entity.
DbLogController::eventDetails in core/modules/dblog/src/Controller/DbLogController.php
Displays details about a specific database log message.
UserCancelTest::testUserAnonymize in core/modules/user/src/Tests/UserCancelTest.php
Delete account and anonymize all content.
UserNameFormatterTest::testFormatter in core/modules/user/src/Tests/Field/UserNameFormatterTest.php
Tests the formatter output.

File

core/modules/user/src/Entity/User.php, line 412
Contains \Drupal\user\Entity\User.

Class

User
Defines the user entity class.

Namespace

Drupal\user\Entity

Code

public static function getAnonymousUser() {
  if (!isset(static::$anonymousUser)) {

    // @todo Use the entity factory once available, see
    //   https://www.drupal.org/node/1867228.
    $entity_manager = \Drupal::entityManager();
    $entity_type = $entity_manager
      ->getDefinition('user');
    $class = $entity_type
      ->getClass();
    static::$anonymousUser = new $class([
      'uid' => [
        LanguageInterface::LANGCODE_DEFAULT => 0,
      ],
      'name' => [
        LanguageInterface::LANGCODE_DEFAULT => '',
      ],
    ], $entity_type
      ->id());
  }
  return clone static::$anonymousUser;
}