function CommentPermalinkFormatter::getEntityUrl

Same name and namespace in other branches
  1. 9 core/modules/comment/src/Plugin/Field/FieldFormatter/CommentPermalinkFormatter.php \Drupal\comment\Plugin\Field\FieldFormatter\CommentPermalinkFormatter::getEntityUrl()
  2. 8.9.x 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()

Gets the URI elements of the entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity object.

Return value

\Drupal\Core\Url The URI elements of the entity.

Overrides StringFormatter::getEntityUrl

File

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

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.