Closed (fixed)
Project:
Content Construction Kit (CCK)
Version:
6.x-1.x-dev
Component:
Views Integration
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
6 Dec 2006 at 03:38 UTC
Updated:
24 Dec 2006 at 02:30 UTC
CCK fields with automatic database storage have no way to identify which node they originate from when output by a view. The universal views handler for content fields calls content_format() as:
content_format($field, $item, $field_data['options']);
So when any field module's hook_formatter() is called, no node information is passed to that function. Here's a one-line patch which passes the pseudo node object $data to content_format, so hook_formatter will be able to discern which node the field data originates in.
Index: content_views.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck/content_views.inc,v
retrieving revision 1.2
diff -u -r1.2 content_views.inc
--- content_views.inc 24 Oct 2006 12:16:16 -0000 1.2
+++ content_views.inc 6 Dec 2006 03:34:31 -0000
@@ -101,7 +101,7 @@
$view_column_name = 'node_data_'. $field['field_name'] .'_'. $attributes['column'];
$item[$column] = $data->$view_column_name;
}
- return content_format($field, $item, $field_data['options']);
+ return content_format($field, $item, $field_data['options'], $data);
}
/**
The $data object is not in fact a node object, but it does contain the nid so fields can load the node themselves if necessary. I imagine a node_load for every field in a view might have a performance impact.
Comments
Comment #1
yched commentedCCK fields with automatic database storage have no way to identify which
node they originate from when output by a view
CCK fields have no way to identify which node they originate from. In Views or in 'regular' node view.
This is currently by design - what's your use case for this ?
Comment #2
karens commentedI think this is a good idea, and I have had situations where this would have been helpful. The data already exists, so we are not doing any extra work. I don't have time to actually text the patch right now, but it looks like it would work.
Comment #3
karens commentedSorry yched! Looks like we cross-posted. The $data item is a Views object which has already been generated and it always contains the $nid, and the content_format function already is expecting an optional $node object, so this seems like a reasonable thing to do and costs nothing. Fields that don't need that info can ignore it. Do you see any problem with doing this? I may be missing something.
Comment #4
yched commentedcontent_format function already is expecting an optional $node object
Yes, I overlooked this. If so, then it's OK and my "so-so" comment does not hold :-)
Comment #5
quicksketchGreat (preemptive) thanks for putting this in!
@yched A use case for me is linking to full node page from a field. Imagefield automatically creates several different options for viewing each size available in imagecache. It would be useful to be able to provide the option in Views for thumbnails to link to the original node in which they are contained, but this currently would be very difficult without any node information available to the field.
Comment #6
yched commentedComment #7
yched commentedhttp://drupal.org/node/102357 has been marked a duplicate of this (different consequence of $data not being passed to the formatter)
Comment #8
RayZ commentedI confirm that this fixes http://drupal.org/node/102357 (i.e. this is a bug fix, not just a feature), so, unless someone thinks otherwise, I think it's RTBC.
Comment #9
yched commentedcommitted - thanks quicksketch
(er I just notice I forgot the credit in the cvs log...)
Comment #10
quicksketchThanks!
Comment #11
(not verified) commented