You are here

public function Comment::getAuthorName in Drupal 10

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

File

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

Class

Comment
Defines the comment entity class.

Namespace

Drupal\comment\Entity

Code

public function getAuthorName() {

  // If their is a valid user id and the user entity exists return the label.
  if ($this
    ->get('uid')->target_id && $this
    ->get('uid')->entity) {
    return $this
      ->get('uid')->entity
      ->label();
  }
  return $this
    ->get('name')->value ?: \Drupal::config('user.settings')
    ->get('anonymous');
}