diff --git a/core/modules/comment/src/Entity/Comment.php b/core/modules/comment/src/Entity/Comment.php index 03887fcd42..93c472760f 100644 --- a/core/modules/comment/src/Entity/Comment.php +++ b/core/modules/comment/src/Entity/Comment.php @@ -404,8 +404,8 @@ public function setSubject($subject) { * {@inheritdoc} */ public function getAuthorName() { - if ($user = $this->get('uid')->entity) { - return $user->label(); + if ($this->get('uid')->target_id) { + return $this->get('uid')->entity->label(); } return $this->get('name')->value ?: \Drupal::config('user.settings')->get('anonymous'); } @@ -424,9 +424,8 @@ public function setAuthorName($name) { public function getAuthorEmail() { $mail = $this->get('mail')->value; - $user = $this->get('uid')->entity; - if ($user && $user->id() != 0) { - $mail = $user->getEmail(); + if ($this->get('uid')->target_id != 0) { + $mail = $this->get('uid')->entity->getEmail(); } return $mail;