I'm having a problem overriding theme_date_display_combination, and I know this issue has been up a couple of times, but they all seem to end with "clearing the cache helped the problem" - and I've already tried that, several times... Drupal version is 6.16.

Just a short intro: I am making modifications to the Calendar - Upcoming view, where it is set to format the date as Short.

In my theme's template.php, I've created a function phptemplate_date_display_combination , in which I for test purposes currently only return "TEST". But for some reason, it insists on using theme_date_display_combination instead. I've tried to do some stacktracing, and it seems that theme_date_display_combination is directly registered as a hook to date_formatter_short, which makes includes/theme.inc use it, instead of using my phptemplate_date_display_combination.

I am completely new to Drupal, but thinks its a great framework :-) I've looked into date.module, and from what I can see, date_display_combination itself is not registered as a hook (is it supposed to be?). Also, there is a foreach, that hooks all date_formatter_* directly to theme_date_display_combination. I suspect it should be hooked to just date_display_combination, and let Drupal figure out the rest, but I'm not sure.

But, from here I'm stuck, in lack of a deeper understanding of the Drupal framework. So, I hope someone can help me. What am I missing?

Thanks in advance :-)

Comments

gwtt’s picture

I thought I was going to have a smart answer to this, but even after reading #592796: Date Filters not working in Views when multiple date fields are used I still see stuck on this. My version of theme_date_display_combination just won't get recognized. I guess I have to implement hook_theme_registry_alter in a module, but I'm trying to do that as a last resort...

Did you ever figure this out?

gwtt’s picture

Status: Active » Closed (works as designed)

OK, now I do have something smart to say. You have to override date_formatter_short like so:

function themename_date_formatter_short($element) {
return themename_date_display_combination($element);
}

obviously defining themename_date_display_combination.

It's confusing because several date formatters use theme_date_display_combination. That's what got me. I overrode default and short, but not long, until not long (ha, ha) after I contacted the OP of the other issue.

Well, if anyone stumbles upon this, hopefully it'll help.

I guess I'll mark it as by design too since no module changes are needed?

Kevin

jhDrupNewbie’s picture

Hi again

Thanks for looking into the issue :-) Although, I must admit I'm not quite sure I understand your solution %) Wouldn't it mean, that the themename_date_display_combination would be used all over the site? (I'm just a bit confused, I'm not seeing the entire picture that clear).

What I did at the time, was to override views-view-field--calendar--block-1--field-dato-value.tpl.php , and do str_replace('/'.date('Y'), '', $output) . It sort of solved part of what I wanted to do (remove the year-part of the date, if the date is this year).

What I also wanted to do, was convert "2011-05-20 12:00 - 2011-05-02 15:00" into "2011-05-20 12:00 - 15:00" - that is, if the start-date and end-date are the same, only show one of them. This is only relevant for my "Upcoming"-block layout, not the other calendar pages/blocks. I couldn't do this (well, not easily, at least) when overriding the view, since I've only got access to the one date instead of both. There may be some other clever way of doing it, but I just thought theme_date_display_combination would be the obvious place.

But, I'll look into your solution, and try to figure out if it will solve the problem :-)

jcfiala’s picture

So, like gwtt said, the problem is that theme_date_display_combination() isn't really a theme function. Sure, it starts with 'theme_', but it's not linked in with date_theme anywhere. Instead, date_theme points various theme functions to theme_date_display_combination. So the best thing to do is something like this:

1) In your theme, which I will call 'foobar' for clarity, implement foobar_date_display_combination and make your changes inside of it.

2) Add this to your theme:

function foobar_theme() {
  $themes = array(
    'date_formatter_default' => array(
      'arguments' => array('element' => NULL), 
      'function' => 'foobar_date_display_combination'),  
  );
  // Table isn't available first time date_theme() is called in update.php.
  if (db_table_exists('date_format_types')) {
    $format_types = date_get_format_types('', TRUE);
    if (!empty($format_types)) {
      foreach ($format_types as $type => $type_info) {
        $themes['date_formatter_' . $type] = array(
          'arguments' => array('element' => NULL), 
          'function' => 'foobar_date_display_combination',
        );
      }
    }
  }
  return $themes;
}

Usually you don't need a hook_theme in a theme, but this time you do, because we're adding something more complicated to the theme than a usual replacement.

gagarine’s picture

Version: 6.x-2.4 » 7.x-2.x-dev
Status: Closed (works as designed) » Fixed

In D7 you can directly create a function yourthem_date_display_combination($vars) in your template.php without the need of hook_theme.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.