views:

84

answers:

3

Hi everyone,

I am trying to theme a calendar view, is there a way to override the theming path with a module instead of overwriting the template files?

I want to create a module that overrides the theming functions so I can include the template files in my module instead of the calendar module.

thx in advance

A: 

I don't think you can do something like that in a module, at least not in a clean way.

Drupal have functionality (modules) and presentation (themes) separated. It makes good sense to divide the two.

  • Cleaner more maintainable code.
  • Functionality needs is common among different sites.
  • Presentation and functionality is often done by different people (developers and themers)

So I wouldn't be surprised if you could do something like this in a module. But you would be working against Drupal, have a hard time doing it, and with no good reason.

If you want to create reusable styles, template overrides etc, use the sub theme system instead.

googletorp
yes, that is the problem, calendar doesn't have hooks so I have to override it's theming. I also want to change some functionality but I can't extend the module for as far as I can see
Nealv
In some cases, one needs to build a functionality on top of an existing modules and requires some default presentation elements to be added to an existing template. In these cases, templates are is welcome in a module. For instance, one module can provide a custom custom ''dashboard'' page build with Views that need some modification to the default Views' templates.
mongolito404
A: 

It seems like what you're looking to do here is rewrite how the calendar module functions, in a way that completely replaces normal calendar behavior before the theme layer has a chance to meddle with it.

In these (hopefully rare) cases, the best thing to do is create your own fork of calendar as a new module, with the existing calendar code as a starting point. Modifying the module code directly will be much easier than trying to hack Drupal's basic functionality/display interactions.

I normally wouldn't recommend this, but it seems appropriate in your case.

Be sure to send any improvements back to the calendar devs so that we all can benefit :)

anschauung
Maybe I can write a hook in the calendar module, and check if a module exercises the hook and then cancel default behaviour. then upload it as a patch?
Nealv
Even better, I'd say :) But, you'll want to implement the hook a little differently than you described, since hooks aren't usually meant to replace eachother or override normal behaviors. Rather than having hooks cancel the default behavior, you should have the hook *replace* the default behavior, then move the original behavior into an instance of the module calling it's own hook.
anschauung
user_user is a good example of how other modules have implemented overridable default behaviors using hooks.
anschauung
+1  A: 

You can override views template in a module, see the "Theming your views in your module" in the Using default views in your module page of Views' Advanced Help. Since Calendar is a views plugin, I think the basic behaviors of Views templating applies. If declaring your own themeable output in your hook_theme($existing, $type, $theme, $path) doesn't work for a Calendar view, you may need to use hook_theme_registry_alter(&$items).

mongolito404