I am trying to add some markup around the number of comments link in the standard node links. I want to do this so I can theme the number of comments as a little comment bubble and hide the text (possibly only on mobile).
I can get this far:
function mytheme_preprocess_links__node(&$variables) {
if (isset($variables['links']['comment-comments'])) {
$title = $variables['links']['comment-comments']['text'];
$count = 7 // need to get the actual count in here.
$variables['links']['comment-comments']['link']["#title"] = \Drupal::translation()->formatPlural($count, ''<span class="comment-count">1</span> <span class="comment-text">comment</span>', '<span class="commment-count">@count</span> <span class="comment-text">comments</span>');
}
}
When I dsm the $title variable I can see that the comment count is in there, I just can't figure out how to get it out into the $count variable. Any help?