D6 Adding an image to a node for viewing
I'm hooking nodeapi op=view and I have the node I hook and another in the db. The one I hook has field_image which, when hooked, is [0]=>NULL I load a node from the db, which also has an image field (both are CCK imagefields). I want to add its image to the original node, however, I need at this point not to add it to field_image, but to $node->content->field_image. The problem is that the structure of ->content is pretty convoluted, ending ultimately in data that is the same as what I've copied (when I look at a node with an image), but I can't seem to cause that to happen. I tried adding the image structure from the source node directly: $node->content->{$field_name}['field']['items'][$key]['#item'] = $image_structure; but that seems to cause more convolution rather than ending up like the $node->content structure from the source node when I display it. -- Ayen Designs 388 Bullsboro Drive #105 · Newnan, Georgia 30263 404-271-9734 Web:ayendesigns.com <http://ayendesigns.com> Blog: theAccidentalCoder.com <http://theaccidentalcoder.com> Drupal: j. ayen green <http://drupal.org/user/367108> IRQ: j_ayen_green IM (Yahoo) baalwww (MSN) baalwww@yahoo.com Skype: ayendesigns Ayen Designs is a tradename of the computer services division of
On the secondary node, try implementing node_build_content(), which should provide to you the secondary $node->content array, or I think you might get this by calling node_invoke_nodeapi($node, 'view', $teaser, $page) directly. See the internals of node_build_content() http://api.drupal.org/api/drupal/modules--node--node.module/function/node_bu... Keep in mind this *will* invoke hook_nodeapi($op = 'view') for the secondary node, which will call your hook_nodeapi() *again,* so make sure you aren't doing anything redundant or getting stuck with infinite recursion somehow. On Mon, Jan 31, 2011 at 10:50 PM, <jeff@ayendesigns.com> wrote:
I'm hooking nodeapi op=view and I have the node I hook and another in the db. The one I hook has field_image which, when hooked, is [0]=>NULL
I load a node from the db, which also has an image field (both are CCK imagefields). I want to add its image to the original node, however, I need at this point not to add it to field_image, but to $node->content->field_image. The problem is that the structure of ->content is pretty convoluted, ending ultimately in data that is the same as what I've copied (when I look at a node with an image), but I can't seem to cause that to happen. I tried adding the image structure from the source node directly:
$node->content->{$field_name}['field']['items'][$key]['#item'] = $image_structure;
but that seems to cause more convolution rather than ending up like the $node->content structure from the source node when I display it.
--
Ayen Designs 388 Bullsboro Drive #105 · Newnan, Georgia 30263 404-271-9734 Web:ayendesigns.com Blog: theAccidentalCoder.com <http://theaccidentalcoder.com> Drupal: j. ayen green <http://drupal.org/user/367108> IRQ: j_ayen_green IM (Yahoo) baalwww (MSN) baalwww@yahoo.com Skype: ayendesigns
Ayen Designs is a tradename of the computer services division of
I'm a little befuddled... do I replace the node's image field with the desired one, and then invoke it to rebuild the content portion, or do I invoke it and then replace the field within the content portion? On 02/01/2011 02:39 AM, Carl Wiedemann wrote:
On the secondary node, try implementing node_build_content(), which should provide to you the secondary $node->content array, or I think you might get this by calling node_invoke_nodeapi($node, 'view', $teaser, $page) directly. See the internals of node_build_content() http://api.drupal.org/api/drupal/modules--node--node.module/function/node_bu...
Keep in mind this *will* invoke hook_nodeapi($op = 'view') for the secondary node, which will call your hook_nodeapi() *again,* so make sure you aren't doing anything redundant or getting stuck with infinite recursion somehow.
The problem doesn't seem to be getting to the $node->content structure. That's present in $node when I hook during op=view. The problem seems to be getting the data into the right place in a cck image field in $node->content. If I were copying the body text from one node the one being viewed, I could just set $node->content->body['#value'] equal to the new text, but $node->content->my_cck_imagefield doesn't have a '#value', the field info is at $node->content->my_cck_imagefield['field']['items'][0]['#item'] when I hook, that element only contains #delta=>0 then I set #item = the array containing [fid] => 11 [list] => 1 [data] => Array ( [description] => [alt] => [title] => ) [uid] => 1 [filename] => myimage.jpg [filepath] => sites/mydomain.com/files/myimage.jpg [filemime] => image/jpeg [filesize] => 174602 [status] => 1 [timestamp] => 1296425237 ) and the dsm() output of the node after that shows that #item still only contains #delta=>0, so I'm missing the piece of how/where I replace the field contents.
participants (2)
-
Carl Wiedemann -
jeff@ayendesigns.com