Can someone help me with this?

I have created a view that gives me a table of certain fields. Now I would like to add a "bulk operation" that lets users add an automatic comment to that specific node.

I have tried to ad a rule (component) and this was the result.

I have activated PHP-filter mode and tried with a component with "Execute custom PHP code".

The code in the component

$comment = new stdClass();
$comment->nid = $node->nid; // nid of a node you want to attach a comment to  (er stond 1)
$comment->cid = 0; // leave it as is
$comment->pid = 0; // parent comment id, 0 if none
$comment->uid = $user->uid; // user's id, who left the comment
//$comment->mail = 'email@example.com'; // user's email
//$comment->name = 'User name'; // If user is authenticated you can omit this field, it will be auto-populated, if the user is anonymous and you want to name him somehow, input his name here
//$comment->thread = '01/'; // OPTIONAL. If you need comments to be threaded you can fill this value. Otherwise omit it.
//$comment->hostname = '127.0.01' // OPTIONAL. You can log poster's ip here
$comment->created = time(); // OPTIONAL. You can set any time you want here. Useful for backdated comments creation.
$comment->is_anonymous = 0; // leave it as is
//$comment->homepage = ''; // you can add homepage URL here
$comment->status = COMMENT_PUBLISHED; // We auto-publish this comment
$comment->language = LANGUAGE_NONE; // The same as for a node
$comment->subject = 'Comment subject';
$comment->comment_body[$comment->language][0]['value'] = 'Afgehaald'; // Everything here is pretty much like with a node
$comment->comment_body[$comment->language][0]['format'] = 'filtered_html';
//$comment->field_custom_field_name[LANGUAGE_NONE][0]['value'] = ‘Some value’; // OPTIONAL. If your comment has a custom field attached it can added as simple as this // preparing a comment for a save
comment_submit($comment); // saving a comment

But when I go to the view and execute the operation, he asks for an identifier. But I want him to directly add the comment.

What I mean with the identifier

Can someone help me with this? Or is there another way?

  • 1
    I added global $user; and it worked... :-s – carlo Oct 12 '12 at 10:00

If I'm going right with your requirement that you want an add comment link with every node in view result listing of nodes.

You should add a relation first to that node with comment by using node reference/entity reference by using referece from url widget type. Your requirement is same like posting answers node on the specific question node. enter image description here

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.