I'm looking to edit some Twig templates for certain form elements, but I need template suggestions only for certain form IDs. How do I go about that?
I currently have the following functions in my .theme file:
function exmaple_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'user_register_form') {
// Something here to alter suggestions of form elements only for the form with the ID 'user_register_form'
}
}
function example_theme_suggestions_form_element_alter(array &$suggestions, array $variables, $hook) {
if (isset($variables['element']['#id'])) {
$suggestions[] = $hook . '__' . str_replace('-','_', $variables['element']['#id']);
// This works but returns global form element suggestions
// For example 'form-element--edit-mail.html.twig' which affects all email edit form elements
// I need suggestions like 'form-element--user-register-form--edit-mail.html.twig'
}
}