I try to add a custom css class to a form element inside my address field for e.g the postal_code
field and another class to the given_name
and family_name
field.
I tried it with a my_theme_theme_suggestions_form_element_alter
. But then I have to extend all the twig files like form-element--equal-width-column.html.twig
, for just adding the css class.
function my_theme_theme_suggestions_form_element_alter(array &$suggestions, array $variables, $hook) {
if (in_array($variables['element']['#attributes']['class']['0'], ['family-name', 'given-name'])) {
$suggestions[] = $hook . '__equal_width_column';
}
}
Is it possible to just add a css class to specific form-elements div's, so I don't have to extend all those twig files?