Last active
September 15, 2024 03:34
-
-
Save wesruv/1f5a44211c6d09e20890a40c9574dd84 to your computer and use it in GitHub Desktop.
Force Drupal to show what timezone a date is being set in π
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 template_preprocess_fieldset(). | |
*/ | |
function muh_module_preprocess_fieldset(&$variables) { | |
// Figure out if this is a "date field" fieldset | |
$hasElementValueType = isset($variables['element']) && isset($variables['element']['value']) && isset($variables['element']['value']['#type']); | |
if ($hasElementValueType && $variables['element']['value']['#type'] == 'datetime' && isset($variables['element']['value']['#date_timezone'])) { | |
// Show what timezone the date field is using as the fieldset description | |
$timezone = $variables['element']['value']['#date_timezone']; | |
if (!empty($timezone)) { | |
$variables['description_display'] = 'after'; | |
$variables['description']['content'] = new TranslatableMarkup( | |
'Date will be set in %timezone timezone', | |
array( | |
'%timezone' => $timezone | |
) | |
); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment