Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Comment.php

function Comment::getAuthorName

Overrides CommentInterface::getAuthorName

1 call to Comment::getAuthorName()
Comment::getOwner in core/modules/comment/src/Entity/Comment.php
Returns the entity owner's user entity.

File

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

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');
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal