I have a date field with both from and to values and number of values = 1, and I have to print the field separately from the node template. So in "display values" settings I have "exclude" checkbox turned on for the field.
However, I found that printing the field using content_format() function like I'm used to doesn't work. After some troubleshooting I've found that theme_date_display_combination() has a bug inside (or it's too smart to be a generic function). It has following block of code:
// If this is a full node or a pseudo node created by grouping
// multiple values, see exactly which values are supposed to be visible.
if (isset($node->$field_name)) {
$node = date_prepare_node($node, $field, $type_name, $context, $options);
// Did the current value get removed by formatter settings?
if (empty($node->{$field_name}[$item['#delta']])) {
return $output;
}
// Adjust the $element values to match the changes.
$element['#node'] = $node;
}
I've found that in my case $item array doesn't have "#delta" key, so the function terminates without printing anything.
Comments
Comment #1
sbandyopadhyay commentedI found the same exact bug, and did a backtrace to find where exactly the
$item['#delta']comes from -- and therefore, why it isn't appearing in our$item.First, my use case:
I'm pulling up a node through
node_load()and rendering the field like this:Second, the problem:
$item['#delta']is actually first set in the following code snippet fromcontent_field($op='view'):This
content_field($op='view')is called in only two places (as far as I can tell).First place that
content_field($op='view')is called:content_view_field()Second place that
content_field($op='view')is called:_content_field_invoke_default($op='view'), which is called by...content_view(), which is CCK's implementation of hook_nodeapi's $op='view'Could we fix our problem by calling
content_view_field()orcontent_view()instead? No, because:content_view_field()requires the field definition, and we don't have the field definition when we're pulling it in throughnode_load().hook_nodeapi($op='view')are only triggered when the page is actually being loaded for viewing -- not throughnode_load().content_field($op='view')in some applications -- especially when it's going to be needed over multiple nodes.So, we need to accept that there are legitimate use cases where
$item['#delta']will not be set.Finally, the solution:
Checking if
isset($item['#delta'])ought to be sufficient to avoid the unwanted triggering of thereturn $output;in the next line. That's what the attached patch does.Comment #2
sbandyopadhyay commentedMarking as needs review.
Comment #3
sbandyopadhyay commentedUpdating the title to be simpler and more to the point.
Comment #4
jarune commentedpatch in #1 works for me
Comment #5
devkinetic commentedI can also confirm that this resolves the issue presented.
Applied the patch from #1 and added the following to theme_preprocess_node
Comment #6
DanielFbrg commentedSubscribing! And thanks for the patch
Why hasn't this been submitted since last year...?
Comment #7
damienmckennaUnfortunately the D6 version of this module is no longer supported, but we appreciate the time you put into this. If this problem is relevant for D7 too, please reopen the issue. Thanks.