You are here

protected function CommentPermalinkFormatter::getEntityUrl in Drupal 9

Same name and namespace in other branches
  1. 8 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 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;
}