Skip to content

Instantly share code, notes, and snippets.

@gheydon
Last active August 24, 2022 04:46
Show Gist options
  • Save gheydon/c630ff933301611c8dc339e2863343b8 to your computer and use it in GitHub Desktop.
Save gheydon/c630ff933301611c8dc339e2863343b8 to your computer and use it in GitHub Desktop.
When dealing with checkboxes, the #title that you use is sometimes not very good to be used with error messages. In this case you can add the '#element_title' to your element and it will replace the this title with so the original title can be used for the error messages
/**
* Implements hook_preprocess_HOOK().
*
* HOOK: 'form_element'
*/
function example_preprocess_form_element(&$variables) {
if (isset($variables['element']['#element_title'])) {
$variables['label']['#title'] = $variables['element']['#element_title'];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment