Skip to content

Instantly share code, notes, and snippets.

@wesruv
Last active September 15, 2024 03:34
Show Gist options
  • Save wesruv/1f5a44211c6d09e20890a40c9574dd84 to your computer and use it in GitHub Desktop.
Save wesruv/1f5a44211c6d09e20890a40c9574dd84 to your computer and use it in GitHub Desktop.
Force Drupal to show what timezone a date is being set in πŸ˜‘
<?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