3

I'm working in a custom module that displays date fields. I want to be able to change the date's timezone programmatically.

I've tried implementing hook_views_pre_render(), but that doesn't allow me to format the field value. I'd really like to do the theming inside my module code since that's where the logic is regarding my timezone.

As a total hack, I could use hook_views_post_render(), but then I'd be doing search/replace on the text and that seems like a poor solution.

What other hooks inside my module are available?

1 Answer 1

2

Okay, so after a little more googling I found my own answer on a thread on d.o that address this issue with sample code (which I'm condensing a bit):

<?php
/**
 * Implements HOOK_preprocess_views_view_fields().
 */
function MYTHEME_preprocess_views_view_fields(&$vars) {
  $view = $vars['view'];

  //Replace 'VIEW_NAME' with the machine_name of your view.
  if($view->name == 'VIEW_NAME') {

    //This for loop iterates over all fields in this view.
    foreach ($vars['fields'] as $id => $field) {

      //Custom formatting logic goes here....

      //Set the field value (not the surrounding tags) here.
      $vars['fields'][$id]->content = 'my new value';        
    }
  }
}
?>

NOTE Make sure you replace "MYTHEME" with the name of your theme or module in order for this work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.