Jump to:
| Project: | Calendar |
| Version: | 6.x-2.2 |
| Component: | Miscellaneous |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
I ran into a problem with the Date module and then found a Date/Calendar shared problem that I think belongs in the Calendar issue queue rather than the Date queue (...where I posted this first).
This Date issue patch - http://drupal.org/node/385688#comment-1839132 - solved the first half of the problem. Now for the second half of the problem.
(After applying Noahb's patch...)
The data still doesn't show up on the calendar. This is because in calendar.inc, function calendar_build_nodes() the $items array looks like this:
Array
(
[0] => stdClass Object
(
[nid] => 12
[node_node_data_field_content_reference_nid] => 11
[node_data_field_show_thumb_field_show_thumb_fid] =>
[node_data_field_show_thumb_field_show_thumb_list] => 1
[node_data_field_show_thumb_field_show_thumb_data] => a:2:{s:3:"alt";s:0:"";s:5:"title";s:0:"";}
[node_data_field_show_thumb_nid] => 12
[node_type] => video
[node_data_field_show_date_nid] =>
[node_node_data_field_content_reference_node_data_field_show_date_field_show_date_value] => 2009-08-10T00:00:00
[raw] => stdClass Object
(
[nid] => 12
[node_node_data_field_content_reference_nid] => 11
[node_data_field_show_thumb_field_show_thumb_fid] => 5
[node_data_field_show_thumb_field_show_thumb_list] => 1
[node_data_field_show_thumb_field_show_thumb_data] => a:2:{s:3:"alt";s:0:"";s:5:"title";s:0:"";}
[node_data_field_show_thumb_nid] => 12
[node_type] => video
[node_data_field_show_date_field_show_date_value] =>
[node_data_field_show_date_nid] =>
[node_node_data_field_content_reference_node_data_field_show_date_field_show_date_value] => 2009-08-10T00:00:00
)
[unknown] => Click to explore
)
...
)Notice that there is no "calendar_fields" object.
This is suppose to be present in $items (when i manually add it, all is well):
[calendar_fields] => stdClass Object
(
[node_data_field_show_date_field_show_date_value] => 2009-08-10T00:00:00
)The calendar_fields data is added when the Date field does not use a relationship. However in my case i need to use the relationship since my date data is coming from the related node.
I've narrowed this down to theme.inc, function template_preprocess_calendar():
$calendar_fields = date_api_fields();
$calendar_fields = array_keys($calendar_fields['alias']);The problem is that date_api_fields() doesn't take into account the possibility of relationships and how that will change the field names.
IE: "node_data_field_show_date_field_show_date_value" will look like "node_node_data_field_content_reference_node_data_field_show_date_field_show_date_value" when a relationship is used.
Here's my solution...
This is a HACK but it works. This checks view fields (with relationships) if the standard date field name exists within it, and if so, gives it the related field's value.
On line 98 in theme.inc of 2.0-rc6, I added:
// HACK: handle field names that use relationships.
if ($field->options['relationship'] !== 'none') {
foreach ($calendar_fields as $cfield) {
if (is_numeric(strpos($key, $cfield))) {
$key = $cfield;
}
}
}I was going to make a patch against 2.2 but I see some code changes around where this snippet goes. I don't have time to test against 2.2 and figure a patch against 2.0-rc6 (that I'm using) would be useless for most. I've still included a patch against 2.0-rc6 as reference for anyone who wants to try this with a newer version.
NOTE: This patch will definitely fail against 2.2 and probably most versions besides rc6.
| Attachment | Size |
|---|---|
| calendar_relationship_date_hack.patch | 644 bytes |
Comments
#1
Hi -
First off, thank you for the wonderful module. It's really well implemented and is helping me out a ton. I'm fairly new to Drupal (extensive coding experience using other technologies) and have found both the code and overall community to be exceptional.
I just want to post an update because I am having the same issue described by nick_robillard. I applied this patch to Date:
http://drupal.org/node/385688#comment-2218938
and then added the following,
// HACK: handle field names that use relationships.if ($field->options['relationship'] !== 'none') {
foreach ($calendar_fields as $cfield) {
if (is_numeric(strpos($key, $cfield))) {
$key = $cfield;
}
}
}
, to line 106 in the 2.2 version of theme.inc and it appears to (at least partially) be working.
I am currently seeing events (based on a Date found in a related node) displayed in the calendar for today only, but nothing in the past or future. I'm not sure if this issue is related to the relationship problem or another configuration issue on my end. I will explore further and post when I have more information.
#2
This would be *such* a useful thing to have. Is there any progress on getting a fix committed to 2.2?
#3
sub...
#4
Aww man, I hit this issue too while working on a client site. The worst part is that when I go into debug mode and when I test the SQL query, I can see that the thing returns results! The ones I want! But it won't display them.
While stepping through quickly, I noticed that one of the handlers' pre-render functions simply returns nothing. Dunno if that matters. It's SO weird. I couldn't trace exactly where it was failing, but it almost seems like it's a theme function rather than a handler. Nonetheless, things work fine when I don't involve relationships.
Any word on this would be awesome. For now I'm just going to try to work around things with a Computed Field.
I actually get database errors too when trying to use fields through a relationship as the arguments...they are:
user warning: Unknown column 'node_node_data_field_order_node.changed' in 'where clause' query: SELECT node.nid AS nid, node_node_data_field_order.title AS node_node_data_field_order_title, node_node_data_field_order.nid AS node_node_data_field_order_nid, node_node_data_field_order.changed AS node_node_data_field_order_changed, node_node_data_field_order_node_data_field_close_show_date.field_close_show_date_value AS node_node_data_field_order_node_data_field_close_show_date_field_close_show_date_value, node_node_data_field_order.type AS node_node_data_field_order_type, node_node_data_field_order.vid AS node_node_data_field_order_vid, DATE_FORMAT((FROM_UNIXTIME(node_node_data_field_order.changed) + INTERVAL -14400 SECOND), '%Y%m%d') AS node_node_data_field_order_changed_day, node.type AS node_type FROM node node LEFT JOIN content_type_order node_data_field_close_show_date ON node.vid = node_data_field_close_show_date.vid LEFT JOIN content_type_order_item node_data_field_order ON node.vid = node_data_field_order.vid LEFT JOIN node node_node_data_field_order ON node_data_field_order.field_order_nid = node_node_data_field_order.nid LEFT JOIN content_type_order node_node_data_field_order_node_data_field_close_show_date ON node_node_data_field_order.vid = node_node_data_field_order_node_data_field_close_show_date.vid WHERE (node.type in ('order_item')) AND (((DATE_FORMAT(STR_TO_DATE(node_node_data_field_order_node_data_field_close_show_date.field_close_show_date_value, '%Y-%m-%dT%T'), '%Y-%m') <= '2010-06' AND DATE_FORMAT(STR_TO_DATE(node_node_data_field_order_node_data_field_close_show_date.field_close_show_date_value, '%Y-%m-%dT%T'), '%Y-%m') >= '2010-06')) OR ((DATE_FORMAT(ADDTIME(FROM_UNIXTIME(node_node_data_field_order_node.changed), SEC_TO_TIME(-14400)), '%Y-%m') <= '2010-06' AND DATE_FORMAT(ADDTIME(FROM_UNIXTIME(node_node_data_field_order_node.changed), SEC_TO_TIME(-14400)), '%Y-%m') >= '2010-06'))) ORDER BY node_node_data_field_order_changed_day ASC in /home/kevin/public_html/kp3/sites/all/modules/views/includes/view.inc on line 769.
which makes no real sense since I can clearly see it selecting the field earlier on. But don't really have time to dig in a lot, so Computed Field here I come...
#5
#6
Automatically closed -- issue fixed for 2 weeks with no activity.