Example How to add custom class to content field link in Drupal 8 & 9.
function THEMENAME_preprocess_field(&$variables, $hook) { $element = $variables['element']; if ($element['#field_name'] == 'field_link') { $variables['items'][0]['content']['#options']['attributes']['class'][] = 'btn btn-danger'; } }
Similar Posts:
- Drupal: Creating a Computed Entity Field
- how to add bootstrap readmore button to teaser in drupal 8
- How to create custom block in Drupal 8 programmatically
- How to get view mode of node in Drupal 8 & 9
- how to Programmatically update an entity reference field in Drupal 8 & 9
862