Created
June 7, 2016 12:47
-
-
Save pcambra/f39c61210b62a39677f7c03f507b1a58 to your computer and use it in GitHub Desktop.
Add a class to an anchor?
This file contains 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