$field_definition =
$entity->
getFieldDefinition($field_name);
if ($view_mode == 'teaser'
) { // Teaser view: display the number of comments that have been posted,
// or a link to add new comments if the user has permission, the
// entity is open to new comments, and there currently are none.
if ($this->currentUser->
hasPermission('access comments'
)) { if (!
empty($entity->
get($field_name)->comment_count
)) { $links['comment-comments'
] =
[ 'title' =>
$this->
formatPlural($entity->
get($field_name)->comment_count, '1 comment', '@count comments'
),
'attributes' =>
['title' =>
$this->
t('Jump to the first comment.'
)],
'fragment' => 'comments',
'url' =>
$entity->
toUrl(),
];
if ($this->moduleHandler->
moduleExists('history'
)) { $links['comment-new-comments'
] =
[ 'title' => '',
'url' => Url::
fromRoute('<current>'
),
'attributes' =>
[ 'class' => 'hidden',
'title' =>
$this->
t('Jump to the first new comment.'
),
'data-history-node-last-comment-timestamp' =>
$entity->
get($field_name)->last_comment_timestamp,
'data-history-node-field-name' =>
$field_name,
],
];