Forked from pcambra/gist:f39c61210b62a39677f7c03f507b1a58
Created
June 7, 2016 13:43
-
-
Save flocondetoile/070304e52bcdff303630b1a830dcd8d0 to your computer and use it in GitHub Desktop.
Add a class to an anchor?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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