Created
November 11, 2017 02:07
-
-
Save keeganstreet/f554c40de0043939b6208c3417cc8a5e to your computer and use it in GitHub Desktop.
Drupal theme hooks to add a template suggestion for labels based on the associated input type
This file contains hidden or 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
<?php | |
/** | |
* Implements hook_preprocess_HOOK(). | |
*/ | |
function drupalsouth_preprocess_form_element(array &$variables) { | |
$variables['label']['#attributes']['data-element-type'] = $variables['element']['#type']; | |
} | |
/** | |
* Implements hook_theme_suggestions_HOOK_alter(). | |
*/ | |
function drupalsouth_theme_suggestions_form_element_label_alter(array &$suggestions, array $variables) { | |
if (isset($variables['element']['#attributes']['data-element-type'])) { | |
$hook = str_replace('-', '_', $variables['element']['#attributes']['data-element-type']); | |
$suggestions[] = "form_element_label__{$hook}"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment