0

Files (images) are uploaded within a content type with plup and plupload. These images are then displayed through a view.

I would like to have a "commenting" functionality for each uploaded image. I used file_entity to have the images being considered as entities so that each of them can be treated individually within a node.

Drupal built-in comments can only be attached to nodes so I have used reply to have the "commenting" functionality working as an entity.

Now I have a hook_node_insert() in which I loop through the images but how can I create a comment field for each of them?

function MY_MODULE_node_insert($node) {
    if($node->type=="my_content_type"){
        $pictures=$node->field_photos['und'];
        foreach ($pictures as $picture){
            // now what?
        }
    }
} 
  • Try to create one manually (a file with a comment), and output the resulting node (either look at it with a debugger, use drupal_debug or var_dump). Then you will see how it's supposed to be build. – Alice Heaton Apr 9 '13 at 14:36
  • Thanks for your answer! But I don't see how I can add a file with a comment field (from the reply module) manually? – jozi Apr 9 '13 at 14:40
  • The Reply module page says "Such bundles can be attached to any fieldable entity by 'reply field'" - this suggests to me you need to add a field of type 'Reply Field' to your file entity. Once you have that you would be able to add comments using the Reply module (but I may be wrong, haven't used it myself) – Alice Heaton Apr 9 '13 at 14:48
  • Indeed! I already have the field of type "Reply" in my field_config_instance but if I follow instructions as stated there drupal.org/node/1228878#comment-4827038. Problem is that when I run field_create_instance($field_instance), I have an error: FieldException: Attempt to create an instance of field field_reply_comment on bundle image that already has an instance of that field. – jozi Apr 9 '13 at 15:13
  • When you call field_create_instance you are adding a field to the content type. You have already done this, no need to do it again ! When you say you want to add a comment, what you want to add is a value for that field. And when I said "create one manually" I meant using the User Interface. If that's not possible then I don't see the point of the Reply module ! – Alice Heaton Apr 9 '13 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.