0

I'm using a Bootstrap theme and would like to add a glyphicon to the "Add new comment" link so that it comes out something like this:

<a href="..."><span class="glyphicon glyphicon-comment"></span> Add new comment</a>

I've considered overriding the link's default text, but I'm not sure how to do it for this string of text, and I don't like the idea of adding HTML to a translatable string.

Using THEME_preprocess_links(&$variables), I used Kint to explore $variables['links']['comment-add'], but I couldn't find any public methods that would allow me to edit the link contents.

6
  • I am not sure about adding a span inside the link, but cant that THEME_preprocess_links add css classes by ['attributes'] to the link itself? Jan 15, 2016 at 17:40
  • Yep, see this question. But adding the glyphicon class directly to the <a> element isn't how it's done in bootstrap and it affects the formatting of the link's content.
    – Chris
    Jan 15, 2016 at 17:43
  • Bootstrap glyphicons need their own span with no content and no other classes. I usually build this kind of bootstrap with inline templates (the fastest way), but the correct way would be to build a custom link template for this.
    – 4uk4
    Jan 15, 2016 at 17:48
  • Not sure how a custom link template will help here. Links are generated via \Drupal\Core\Utility\LinkGenerator from what I can tell, which does: return $generated_link->setGeneratedLink('<a' . $attributes . '>' . $variables['text'] . '</a>');. It looks like I'd need to form a new link and edit the $variables['text'] section...
    – Chris
    Jan 15, 2016 at 18:13
  • See comment_node_links_alter() and \Drupal\comment\CommentLinkBuilder::buildCommentedEntityLinks()
    – user21641
    Jan 15, 2016 at 19:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.