function CommentPermalinkFormatter::getEntityUrl

Same name in other branches
  1. 8.9.x core/modules/comment/src/Plugin/Field/FieldFormatter/CommentPermalinkFormatter.php \Drupal\comment\Plugin\Field\FieldFormatter\CommentPermalinkFormatter::getEntityUrl()
  2. 10 core/modules/comment/src/Plugin/Field/FieldFormatter/CommentPermalinkFormatter.php \Drupal\comment\Plugin\Field\FieldFormatter\CommentPermalinkFormatter::getEntityUrl()
  3. 11.x core/modules/comment/src/Plugin/Field/FieldFormatter/CommentPermalinkFormatter.php \Drupal\comment\Plugin\Field\FieldFormatter\CommentPermalinkFormatter::getEntityUrl()

Overrides StringFormatter::getEntityUrl

File

core/modules/comment/src/Plugin/Field/FieldFormatter/CommentPermalinkFormatter.php, line 33

Class

CommentPermalinkFormatter
Plugin implementation of the 'comment_permalink' formatter.

Namespace

Drupal\comment\Plugin\Field\FieldFormatter

Code

protected function getEntityUrl(EntityInterface $comment) {
    
    /** @var \Drupal\comment\CommentInterface $comment */
    $comment_permalink = $comment->permalink();
    if ($comment->hasField('comment_body') && ($body = $comment->get('comment_body')->value)) {
        $attributes = $comment_permalink->getOption('attributes') ?: [];
        $attributes += [
            'title' => Unicode::truncate($body, 128),
        ];
        $comment_permalink->setOption('attributes', $attributes);
    }
    return $comment_permalink;
}

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