1

I have a view relating different types of information together. I have a node type and 2 relation types. The base node is related to other nodes using the 2 relations.

Lets say there are 3 fields in the view listing: the base node and 2 other nodes related to the base node:

  • nid of the "base node"
  • nid of a related node (using relation1)
  • nid of another related node (using relation2)

I like to do some action with the base node using views bulk operations. In this custom action I like to use the nids of the other 2 nodes.

My problem is, you can only use one of the three nodes in the action, depending on what you selected in the bulk operations field.

Is there a way to pass ALL three nids?

I know I can use views php to create a hidden field, containing the other two nids and then use the hook_form_submit to hook into the submitted form.

But is there a more elegant way, only to use the custom action, without hooking the submitted views form?

  • Hang on, are you in Drupal 6? – Turion Sep 11 '14 at 8:05
  • No, this question is for D7. I will add the version to the question title... ;-) – schulle877 Sep 11 '14 at 8:24
0

You sort of can already. Create the component with three arguments. It will pass the selected node to the first argument. On the second page of VBO you'll have two more fields to fill in. You can enter tokens here e.g. [yourrelationfield1] for fields of your view.

  • Thank you for thant answer. What component did you mean? Did you mean something like this: function vbo_action($node,$argument2,$argument3,$context) I thought the second argument is always the context... – schulle877 Sep 11 '14 at 7:23
  • I mean a rules component, which is like a rule with arguments. Create it on the rules page. I didn't talk about any code whatsoever. You can do what I said without a single line of code. – Turion Sep 11 '14 at 8:03
  • I also found another solution, see my own answer below. – schulle877 Sep 11 '14 at 8:12
  • Okay, @Turion thank you. I don't use rules for that kind of actions I like to perform. But thank you anyway, perhaps I will take a look and can do some actions without writing the code :-) – schulle877 Sep 11 '14 at 8:23
0

I just found an answer. Just put all the fields you like to use in your custom vbo action into the view. They might be hidden, if they are system fields you don't like to show to the user. Then write your action definition. It is important to set the 'pass rows'-parameter to true.

    /**
    * implements hook_action_info
    *
    * defines the custom actions
    **/
    function MY_MODULE_action_info() {
        $nid_page = menu_get_object();
        if (!isset($nid_page)) $nid_page = arg(1);

      /**
      * NOTE:
      * PLEASE NOTE THAT THE BEHAVIOUR PROPERTY IS NEEDED FOR THE SELECTED ITEM; ALTHOUGH YOU MIGHT NOT CHANGE THE SELECTED ITEM
      * CLEAR CACHES AFTER CHANGING THE action_info_array !!!
      **/         

        return array(
            'MY_MODULE_custom_action1' => array(
                'type' => 'node',
                'label' => 'perform custom actions (WITH form)',
                'configurable' => FALSE,
                'behavior' => array('views_property'),
                'pass rows' => TRUE, /* this passes the entire views row to the $context array */
                'parameters' => array('page_nid'=>$nid_page), /* you can also define some other parameters that are passed via the $context array */
            ),
        );
    }
    /**
    * function to perform vbo actions
    *
    * @param $node
    * selected node entity from view to perform action with
    *
    * @param $context
    * array with context infos like view, options, row...
    *
    **/
    function MY_MODULE_custom_action1(&$node, $context) {
        global $user;
        dpm($node);dpm($context);
        /* row data can be accessed using the $context array */
        $var1 = $context['rows'][0]->field_name[0]['raw']['value'];
    }

Your Answer

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

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