Using form_alter, I added one more form element on the bulk operation page. When I traced into views_bulk_operations_form_submit(), the element is evaluated as form['sel_name']['name']='foo' .

I wanted $form_value['sel_name'] to be merged into the arguments when my own defined node_operation() is called.

I tried all sort of things. One method I tried was:

  $operations = array(
    'register' => array(
      'label' => t('myop'),
      'callback' => 'node_operations_myop',
      'callback arguments' => '$form_values[\'sel_name\']',
  ),

It failed. My hunch is that $args = array_merge(array($nodes), $operations[$action]['callback arguments']) treated $form_values['sel_name'] the whole thing as a literal string.

Basically, I need that additional form element passed back to my own operation without hacking views_bulk_operations_form_submit(). Is there a way to do this?

thx.

Comments

newbuntu’s picture

To add insult to the problem, I added the following hack in views_bulk_operations_form_submit():

      if ($form_values['sel_name'])
       {
     	$arr = array(0=>$form_values['sel_name']);
        $args = array_merge(array($nodes), $arr);
       }
      
      call_user_func_array($operations[$action]['callback'], $args);

I traced and saw $args was merged successfully with my parameter right before call_user_func_array(). However, when myop_function($nodes) is called, $nodes doesn't have my new parameter anymore!!! What's the catch? I am lost!

newbuntu’s picture

I know I'm playing with fire! I don't really have a good grasp of php.

When I changed myop_function($node, $extra) to have an extra parameter, now I can get my hacked value. I am going to move on with this for now. However, I don't know what more troubles are in store for me with this type of hacking!

If any you experts see I'm doing stupid things, please let me know before I get seriously burnt.

Thanks.

infojunkie’s picture

Assigned: Unassigned » infojunkie

Node operations are not designed to accept user-defined arguments. On the other hand, actions.module does support user-defined arguments in the manner that you seem to want - and VBO supports this out of the box. I suggest downloading that module (http://drupal.org/project/actions) and checking out the "Change node author" action located in actions.inc:action_node_assign_owner().

infojunkie’s picture

Status: Active » Fixed

Marking as fixed unless anyone has an objection.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

theoldfather’s picture

I see what newbunto is saying. The callback arguments are not being passed to the callback function.