Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save flocondetoile/070304e52bcdff303630b1a830dcd8d0 to your computer and use it in GitHub Desktop.
Save flocondetoile/070304e52bcdff303630b1a830dcd8d0 to your computer and use it in GitHub Desktop.
Add a class to an anchor?
function my_module_entity_view(&$build, EntityInterface $entity, EntityViewDisplayInterface $display) {
if ($entity instanceof FieldableEntityInterface && $entity->hasField('field_name')) {
foreach (Element::children($build['field_name']) as $item) {
$build['field_name'][$item]['#attributes'] = ['class' => 'my-class'];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment