Color stripe based on taxonomy term
Todd Vogel - January 7, 2008 - 18:19
| Project: | Calendar |
| Version: | 6.x-2.x-dev |
| Component: | User interface |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
I've seen some support requests to be able to change the color stripe in the calendar based on taxonomy terms but I didn't see anything in the feature requests. I apologize if that makes this post redundant.
Thank you
tvogel

#1
I second this feature request =)
#2
i too would like to see this happen... subscribing...
#3
Here's a hack to accomplish this. I can't support it. It works for me because I'm only using one calendar on my whole site, and I only have one vocabulary that is used to differentiate event types.
For 5.x-1.7, you'll need to edit calendar.module's calendar_get_nodes function. However, I'm using 5.x-2.x-dev, so this snippet is in calendar.inc's calendar_build_nodes function. Look for:
if ($view->build_type == 'page' && $view->calendar_type != 'year') {$node->stripe = calendar_node_stripe($view, $node, $option['query_name'], $field_field);
}
Then replace it with this code. The 2nd taxonomy_node_get_terms_by_vocabulary argument is your vocabulary's id. If a node has more than one term from that vocabulary, the stripe will be based on the one with the lowest term id. If the node has no terms in that vocabulary, you'll fall back to the regular method of naming stripes, which is to say that they'll be categorized by their content type and date field.
if ($view->build_type == 'page' && $view->calendar_type != 'year') {$term = array_pop(taxonomy_node_get_terms_by_vocabulary($node->nid, 15));
$node->stripe = calendar_node_stripe($view, $node, $option['query_name'], $field_field, $term->name, $term->name);
}
It would be nice to see this implemented properly, but I don't know how it would be done through the Views UI.
(In Calendar 2, the third argument of the calendar_node_stripe is never used in the function, so don't get spooked when you realize that I am passing different arguments than the original function call.)
#4
Thanks, bangpound!
I modified what you gave a bit so that I could easily add this functionality to different calendars, while protecting other calendars from having any changes made.
<?phpif($view->name == 'View_Name'){
if ($view->build_type == 'page' && $view->calendar_type != 'year') {
/*The 4 in the next line of code refers to a taxonomy type. To add another calendar with similar functionality, you'll need to find the appropriate taxonomy ID by going to example.com/admin/content/taxonomy and editing the taxonomy type you want. The number at the end of the URL will be the number you put here.*/
$term = array_pop(taxonomy_node_get_terms_by_vocabulary($node->nid, 4));
$node->stripe = calendar_node_stripe($view, $node, $option['query_name'], $field_field, $term->name, $term->name);
}
}
else {
if ($view->build_type == 'page' && $view->calendar_type != 'year') {
$node->stripe = calendar_node_stripe($view, $node, $field_field, $field_field);
}
}
?>
Excuse the poor formatting. Copy/paste isn't my friend today.
#5
Moving D5 feature requests that aren't going to get into the initial official 5.2 release to be D6 feature requests that could potentially be backported to D5.2.
#6
I would find that a very useful improvement of an already excellent module. But what if a node was attached to more than one taxonomy term? Would several stripes need to be shown?
#7
dond: good question. multiple stripes for a single event could look cluttered and inconsistent. if there's a vocabulary for nodes with a data field, perhaps that's a case for small icons instead of stripes? stripes for single-value vocabularies. icons for multiple-value vocabularies.
#8
I think it will have to be an either/or -- either you do a stripe by content type or by taxonomy term. The code is ready to accept the alternative options, the holdup is altering the UI to give you a way to set stripe colors for taxonomy terms. There could be hundreds of taxonomy terms on a site, so we need to first select a vocabulary, then provide a way to set stripe colors on the terms in that vocabulary. This all needs to go into the place where you set stripe colors for content types, so it will actually need to become a 3-step process:
1) What type of stripe -- content type or taxonomy?
2) If taxonomy, for which vocabulary?
3) Create a settings form like the current content type form with the content type or term options where you can set up the stripe colors
Something like hierarchical select would make this easier to use, although I don't like to add dependencies. I don't have time to work on this now. If someone wants to work on a patch, I'd be glad to look at it.
#9
Hmm... I missed the previous idea, there could indeed be several terms that match.
Well, I'm open to patches if someone wants to figure this out :)
#10
I agree that multiple stripes would be confusing. On the other hand, icons might have to be user definable or at least selectable from a 'vault' of predefined icons. I see problems with that.
My feeling is that small (user-definable) coloured squares or blobs instead of stripes would perhaps work and several could be fitted into the area available to a single stripe at present. If a node were to exceed that limit then perhaps a) that could be indicated by an icon and b) the choice of terms could be prioritised so that only the most important were shown.
In my own case the maximum number would not exceed 4 but I guess there would be wide variation in general.
I would like to help but I'm strictly a gui user not a programmer. I'll test if someone tells me how to install and run 'patches'.
#11
The code is currently set up to take a hex color value and use that to create the stripe. The current method basically adds something like $node->stripe = '#ffcccc', $node->stripe_label = 'Story' to the node, then the templates does something like
'<span style="background-color:#ffcccc">...</span>. Since the color is hard-coded in the html, we don't need to create style sheets with all possible colors, plus colors added this way automatically pick up the highest possible importance so they override any other style that might be trying to affect that stripe.For accessibility, some text is added to the stripe so screen readers can 'see' the label that goes with the stripe selection. The text is drawn in the same color as the background so it becomes invisible to someone looking at the screen.
So changing this method to do something with icons instead of stripes would be a significant change in the way things work.
#12
Thanks for the overview KarenS. I will see if I can put together a patch for the simpler problem of the taxonomy stripes.
Icons/squares/dots/etc. for multi-value vocabularies is a slightly larger problem. I'm no genius PHP programmer, and I'm sure this won't work for every site, but the theme_calendar_node_day, theme_calendar_node_week, theme_calendar_node_month functions can be overriden to create this functionality on a case-by-case basis. If people want taxonomy and content type, it's only a matter of time before they'll want CCK fields too. In a case like this, you'd have to implement your own legend.
#13
I'm looking to use this in 6.x, but can't find this code in calendar 6.x-2.x. Is there a way to do the same thing for 6.x?
Eben
#14
Indeed, an appreciable propriety. Someone know what we're supposed to modify to be able to use it in D6?
Thanks
Julien