function Comment::getDefaultHostname

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

Returns the default value for entity hostname base field.

Return value

string The client host name.

File

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

Class

Comment
Defines the comment entity class.

Namespace

Drupal\comment\Entity

Code

public static function getDefaultHostname() {
    if (\Drupal::config('comment.settings')->get('log_ip_addresses')) {
        return \Drupal::request()->getClientIP();
    }
    return '';
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.