support sub-operations returned from hook_node_operations()

Andrew Schulman - November 5, 2009 - 17:49
Project:Views Bulk Operations (VBO)
Version:6.x-1.8
Component:Integration
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Description

The documentation states that any module offering an implementation of hook_node_operations() will have its operations available to VBO. The Language assignment module implements hook_node_operations() to provide a "Set language" operation at admin/content/node, but that operation isn't available in VBO.

I suspect that the reason for this behavior is that Language assignment uses the variation of its return value in which $operations['Set language']['label'] is not a text string, but an array of sub-operations, one for each of the installed languages. The screenshot shows how this looks at admin/content/node.

This variation is poorly documented in the API-- at the moment I can't find it at all, though I know I've seen it there somewhere-- but it is supported. I swiped the implementation in Language assignment directly from the Add/Remove role operations in user_user_operations().

Can you confirm whether this is the cause of the problem? If it is, I'll try to find a workaround. I know I could define an action to set the node languages, but I'd rather use hook_node_operations(), since I've already implemented it and it uses a node mass update, instead of one at a time.

Thanks,
Andrew.

#1

kratib - November 5, 2009 - 18:12
Category:bug report» support request

You're right, VBO doesn't support sub-operations. It would be useful to support them, but what's more difficult is to inform VBO which function to call when the operation (or sub-operation) is selected. For node operations, VBO looks for the attribute 'callback' that can be part of the operation's description, but it's not in your case, since you directly hook into the admin form. If you have a suggestion for a generic way to let VBO handle these cases, I'll gladly consider it.

#2

Andrew Schulman - November 5, 2009 - 18:58

OK, as I suspected. Thanks for your speedy reply.

Agreed that the problem is which function to call for sub-operations. Well, it seems to me that a common callback function for all of the sub-operations could work just fine here: e.g. if languageassign_node_operations() returns

$operations = array(
  'Set language' => array(
    'label' => array(
      'languageassign-'   => 'Language neutral',
      'languageassign-en' => 'English',
      'languageassign-fr' => 'French',
    ),
    'callback' => 'languageassign_node_operations_callback',
  ),
);

then VBO would only have to do two things:

  1. Populate the selection dropdown with the given main and sub-operations.
  2. Invoke the callback with the key name of the selected operation, or maybe the whole $form_state, as an extra callback argument.

Then the callback would have the information it needed to implement the operations.

I think that would be a nice improvement to VBO, and I'd be glad to take a crack at developing a patch to implement it. It would help a lot if you could point me to the places where these two operations should go-- VBO is pretty complex.

#3

Andrew Schulman - November 5, 2009 - 19:45
Title:hook_node_operations()» support sub-operations returned from hook_node_operations()

populate_operations() in views_bulk_operations_plugin_style.inc

#4

kratib - November 5, 2009 - 21:12

That's right, populate_operations is where operations are discovered and stored. The first loop:

foreach (_views_bulk_operations_get_object_info() as $object_type => $info) {
      $hook_name = $object_type .'_operations';
      foreach (module_invoke_all($hook_name) as $operation) {

iterates over each object type (node, user, comment, etc.), calling hook_{type}_operations each time. You will need to modify the content of the loop to detect labels that are in fact arrays, and create a new operation per label. You will also need to take care of preserving the label key that is supposed to be passed to the callback.

 
 

Drupal is a registered trademark of Dries Buytaert.