Skip to content

Instantly share code, notes, and snippets.

@pcambra
Created June 7, 2016 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pcambra/f39c61210b62a39677f7c03f507b1a58 to your computer and use it in GitHub Desktop.
Save pcambra/f39c61210b62a39677f7c03f507b1a58 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