6077 comments
2357 subscribers
6198 on Twitter
Subscribe! Feed reader E-mail

Drupal fixes: Modifying the entries in Calendar

The Drupal Calendar module is great. You can show view results in a decent-looking calendar easily. However, if you want to show more than what’s provided out of the box, you need to do a bit of undocumented and confusing hacking.

Let’s say that instead of displaying the items, you want to display the number of items. You need to implement hook_calendar_add_items, which, despite its name, actually overrides the items displayed. Your hook_calendar_add_items($view) should return an array of an array of items, which is also confusing, because the receiving function (template_preprocess_calendar in calendar/theme/theme.inc) doesn’t actually do anything with the outermost array, or indeed with multiple entries – it simply takes the last array and sets the items to it.

Each item should be something like this:

$item = new stdClass();
$item->node_title = t('Hello world');
$item->calendar_start_date = $date;
$item->calendar_end_date = $date;
$items[] = $item;

and at the end, you do this:

return array($items);

Your hook_calendar_add_items gets the $view, but not the existing items, so you’ll have to recalculate things using $view->result. Remember: if you return anything, your results will replace the items instead of being added to them.

Because hook_calendar_add_items doesn’t actually do what it advertises, there are probably bugs in this area of code, and this behaviour might change in future releases of Calendar. Be careful when using it. However, it seems to be the easiest way to change Calendar behavior. Caveat developer.

Also useful: http://drupal.org/node/412418

2010-12-24 Fri 10:19

Short URL: http://sachachua.com/blog/p/22014

On This Day...

  • 2012: Blog analysis for 2012: ~133,000 words so far — I reviewed my blog posts in 2012 and rated them on a scale of 1 to 5, where 5 indicates [...]
  • 2011: Quantified Awesome: Building my own time tracker — I took advantage of the holiday break to build my own time tracker into Quantified Awesome. I wanted a simple [...]
  • 2009: How you know your training sessions are working; Remote Presentations That Rock — We facilitated “Remote Presentations That Rock” for the second women’s leadership group a few weeks ago. After watching the video, [...]
  • 2007: Emacs: Choosing between Org and Planner — jaaronfarr asked me why I switched from Planner to Org. Both of them are popular personal information managers for Emacs, [...]
  • 2007: Bugfix: Time estimation — This is a slightly better version of sacha/org-calculate-free-time that can understand prioritized tasks. Also, if you’re working after midnight, it takes into [...]
  • 2006: Back from wakeboarding — We spent the afternoon at the Camsur Watersports Complex. My sisters and I tried wakeboarding. Now I can barely raise my [...]
  • 2006: My favorite blog posts — Here are my other favorite blog posts: 2006.01.07#2: Things every geek should know 2006.02.05#2: Why I like the Emacs editor 2006.03.18#3: Upon reflection 2006.03.26#1: [...]
  • 2006: Thoughts on life — I’ve thought a fair bit about life this year, and I’m getting a better idea of what I want to do. [...]
  • 2006: A year in review: Emacs — Over the last five months, I’ve added all sorts of code to my Emacs to make it a contact relationship management [...]
  • 2006: I keep forgetting that I’m on vacation — Me: “So, what are we doing today?” Mom: “Nothing.” <brain implodes> Hmm. Maybe I should meditate a little bit before going to the [...]
  • 2006: Ay, my sister — So my sister’s drafting a letter to this guy she really likes, and she ends up explaining her feelings in terms [...]
  • 2006: From the Freeciv AI documentation — The code base used to be in a bad shape but it has gotten a lot better. The reason for [...]
  • 2006: Slowly but surely making progress — Goal: inbox zero by New Year! This will be somewhat easier if I don’t check mail between now and then, of [...]
  • 2006: Another day, another sunrise — This time from a watersports resort said to be the best in the world for wakeboarding. I’ll give it a shot, [...]
  • 2005: Fireworks festival — Went to the first day of the international fireworks festival at Manila Bay. Papa wrangled a press pass. =) Took pictures, [...]

Get the highlights as a PDF!

Stories from my Twenties: Highlights from a Decade of Blogging