Drupal 9 - Adding Twig Template Suggestions for Form Elements label_alter

By toswebdev, 5 October, 2022
Drupal 9 - Adding Twig Template Suggestions for Form Elements label_alter
/**
 * Implements hook_theme_suggestions_HOOK_alter().
 */
function customer_feedback_theme_suggestions_form_element_label_alter(&$suggestions, $variables) {
   if (isset($variables['element']['#id'])) {
        $id = str_replace("-", "_", $variables['element']['#id']);
        $suggestions[] = 'form_element_label' . '__' . $id;
    }
}

After adding the above code, you can check the inspect element and see the theme file suggestion shown in the screenshot below.  Here is the link to How to enable theme suggestions in Drupal 9?

After adding the above code, you can check on inspect element and see the theme file suggestion as shown in the screenshot below.

Tags

Comments

All comments go through moderation, so your comment won't display immediately.