Getting current node ID for use in VBO operation I have a view of nodes and I'm using VBO and rules to apply taxonomy terms to the nodes. What I want to do is:


Get the current node's ID (that is, the node with the view block in it).
Get the value of a term reference field from that node.
Apply that value to the term reference field of my VBO selected nodes.


But I'm having problems making menu_get_object work, or any other method of getting the current node's information.

I'm using the "Execute custom PHP" rules action. Here's what my code looks like:

$tagID = 'initialized';

$nodeVBO = $node;  // Storing the $node object sent from VBO

if ($node = menu_get_object()) {
  // Get the nid
  $nid = $node-&gt;nid;
  $nodeID = $nid;
  gets_tag_tid($nodeID);
}

function gets_tag_tid(&amp;$nodeID) {
  global $tagID;
  $node = node_load($nid = $nodeID);
  // Get tag tid from node nid
  foreach ($node-&gt;field_tags[$node-&gt;language] as $item) {
    global $tagID;
    $tagID = $item['tid'];
  }
}

$nodeVBO-&gt;field_tags['und'][0]['tid'] = $tagID;

node_save($nodeVBO);


Sorry for the awkward code, it's adapted from another part of my module.

I get nothing out of the "if" or the gets_tag_tid functions. I have tried echoing the values and reforming the script various ways.

I have never written an operation or an action before so I'm not sure what I can and can't do. I think the problem might be that when VBO performs the operation it changes the URL to /batch?op=start or something like that. 

Can anyone point out what I'm doing wrong or show me a better way?

Thank you

EDIT: I have tried reducing the code to the following:

$VBOnode = $node;
$nid = 'initialized';

$node = menu_get_object();
$nid = $node-&gt;nid;

$VBOnode-&gt;body['und'][0]['value'] = $nid;

node_save($VBOnode);


I was trying to print the nid to see if it was even being retrieved. Nothing is printed in the body field though (not even 'initialized'). To me this indicates that the script is calling menu_get_object(), getting nothing back because the current page is a batch page, thus $node (and subsequently $nid) are set to null values. 

Does anyone know of a way to make the VBO operation execute on the node page without switching to the batch page and redirecting back? Or any other alternative solution that I could try? Thank you
You can patch VBO module - to get optional disable batch.
https://drupal.org/node/1902104

It is working - i get normal token current page url, not batch url.

I need to get current NID - where VBO function runs.

when you will get result - please write it, maybe here.