Same name and namespace in other branches
  1. 8.9.x core/modules/comment/src/Entity/Comment.php \Drupal\comment\Entity\Comment::getOwner()
  2. 9 core/modules/comment/src/Entity/Comment.php \Drupal\comment\Entity\Comment::getOwner()

Returns the entity owner's user entity.

Return value

\Drupal\user\UserInterface The owner user entity.

Overrides EntityOwnerTrait::getOwner

1 call to Comment::getOwner()
Comment::preSave in core/modules/comment/src/Entity/Comment.php
Acts on an entity before the presave hook is invoked.

File

core/modules/comment/src/Entity/Comment.php, line 514

Class

Comment
Defines the comment entity class.

Namespace

Drupal\comment\Entity

Code

public function getOwner() {
  $user = $this
    ->get('uid')->entity;
  if (!$user || $user
    ->isAnonymous()) {
    $user = User::getAnonymousUser();
    $user->name = $this
      ->getAuthorName();
    $user->homepage = $this
      ->getHomepage();
  }
  return $user;
}