3

I need to update term references on nodes without updating the "changed" timestamp on the node. If I use VBO with "modify entity values" as action I can update the term reference but it will also update the "changed" timestamp.

How can I code a custom VBO action?

5

First, an explanation of why the changed timestamp gets updated. Actions can declare the attribute

'behavior' => array('changes_property')

in their hook_action_info entry. This attribute causes VBO to automatically call Entity API's entity_save function after the action has been called. This function ends up calling node_save, which updates the changed timestamp.

To avoid this behavior, simply create your own custom action by implementing hook_action_info in a custom module and follow the action_example of the Examples module. Make sure that your hook_action_info omits the attribute

'behavior' => array('changes_property')

Your action function will need to save the node or any other data by manipulating the database directly, or by making sure that you're using a function that doesn't trigger a node_save call.

| improve this answer | |
  • First, an explanation of why the changed timestamp gets updated ...then I was expecting the explanation on How to create custom VBO action – Strae Oct 2 '12 at 10:59
  • Thank you! I had defined the 'behavior' parameter and it was making my function not work properly. I removed it and it worked! – oranges13 Sep 9 '13 at 20:27
1

The answer by infojunkie is correct, however if you completely remove the attribute rather than just setting it to:

'behavior' => array()

then it will default back to:

'behavior' => array('changes_property')

and then you are back to the original problem. This was a gotcha for me for a while today so hoping to save someone some trouble in the future.

(See plugins/operation_types/action.class.php lines 22-25 in the https://www.drupal.org/project/views_bulk_operations module on drupal.org for details.)

| improve this answer | |
0

It appears that using:

'behavior' => array()

still reverts to the default as the VBO code adds the default if empty($this->operationInfo['behavior']))...

To avoid this set behaviour to something else (made up will do) such as.

'behavior' => array('ignore')
| improve this answer | |

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.