No content when using date argument data from relationship.

nick_robillard - August 10, 2009 - 09:28
Project:Calendar
Version:6.x-2.0-rc6
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

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).

http://drupal.org/node/385688

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.

AttachmentSize
calendar_relationship_date_hack.patch644 bytes

#1

mdgabor - November 3, 2009 - 17:30

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.

 
 

Drupal is a registered trademark of Dries Buytaert.