My question is for D8...
I have a field which is rendered as a link. Let say for simplicity that it will be rendered like this: <a href="url">My Title</a>
I would like to add a bootstrap icon inside the link to get a result like this: <a href="url"><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>My Title</a>
I know that I can take the url and the title from within the preprocess function to reconstruct a new link (#markup)... But is it possible to simply add the icon code somewhere in the array to get the same result?
I am adding some more information to clarify:
1-The field which is rendered as a link is a term reference field rendered as a linked label
2-Here is my try in the preprocess_field function to achieve this
function mymodule_preprocess_field(&$vars) {
$fn = $vars['element']['#field_name'];
switch ($fn) {
case 'my_field':
foreach ($vars['items'] as $key => $item) {
$icon = '<span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>';
$vars['items'][0]['content']['#title']=$icon.$item['content']['#title'];
}
break;
}
}