4

I'm trying to add some custom actions to my Views Bulk Operations, but for some reason, they don't appear in the list.

This is my code (got it from Drupal.org, so I guess this is a working code...)

function publication_action_info() {
  return array(
    'node_unpublish_action' => array(
      'description' => t('Unpublisedh node--'), 
      'type' => 'node', 
      'configurable' => FALSE, 
      'hooks' => array(
        'node' => array('insert', 'update'),
      ),
    ), 
    'node_unpublish_by_keyword_action' => array(
      'description' => t('Unqsdfqsdfpublish node containing keyword(s)--'), 
      'type' => 'node', 
      'configurable' => TRUE, 
      'hooks' => array(
        'node' => array('insert', 'update'),
      ),
    ),
  );
}

So what's wrong with my code or logic to make this thing to work?

1
  • 1
    Both action names (node_unpublish_action, node_unpublish_by_keyword_action) already exist (actions provided by core), which is why VBO ignored them. Commented May 11, 2012 at 14:48

5 Answers 5

5

Try to use configuration>>Actions and create new actions

2
  • where is this??? Commented Oct 20, 2015 at 21:36
  • 1
    @duckx Here: /admin/config/system/actions
    – farjam
    Commented Jan 22, 2016 at 17:18
12

Here is the way, I found for D7...

/**
 * Implementation of hook_action_info().
 */
function MODULE_action_info() {
   $action = array(
    'MY_ACTION_NAME' => array(
      'label' => t('MY ACTION LABEL.'),
      'type' => 'node',
      'configurable' => FALSE,
      'triggers' => array('any'),
    ),
 );
 return $action;
}

/**
 * Action function for MY_ACTION_NAME.
 */
function MY_ACTION_NAME(&$entity, $context = array()) {
  // Your code here.
}

Now just add the action MY ACTION LABEL in VBO list.

3
  • What does "add the action MY ACTION LABEL in VBO list" mean? Where do I add this?
    – user11312
    Commented Apr 23, 2013 at 18:13
  • I assume VBO is Views Bulk Operations...
    – Felix Eve
    Commented Nov 28, 2013 at 10:56
  • As @Michael Greisman mentions below, you have to add the "Execute MY ACTION LABEL" permission for the role to which the user belongs. If you're using an admin user, don't assume the administrator role will already have the permission. You might see the action in the VBO list of available actions to perform, but checking it will not do anything. It won't show up in the operations drop down for the view until the user has the permission to execute it. Similarly, if you've checked 'Each action as a separate button' the button won't show up for the user without that execute permission.
    – dcarrith
    Commented Dec 31, 2014 at 22:25
2

Just a note -- For Drupal 7, IMO @tanmayk's answer is best -- define the action in your custom module using hook_action_info() and the action will then appear in the Configuration > System > Actions window as well as in the VBO list.

But remember that you have to permit the user to use the action (People > Permissions)! Thanks to @autopoietic for triggering that memory.

0

Try using triggers

'triggers' => array('node_presave', 'node_insert', 'node_update'),

instead of

'hooks' => array(
    'node' => array('insert', 'update'),
 ),

Here is worrking exaple of action.

'action_example_node_sticky_action' => array(
      'type' => 'node',
      'label' => t('Action Example'),
      'configurable' => TRUE,
      'triggers' => array('node_presave', 'node_insert', 'node_update'),
),

See action_example in Examples for Developers for more details

Also this article can be usefull: Views Bulk Operations (VBO) development guide.

But notice:

This guide applies to Drupal 6 only, last updated for release 6.x-1.13

1
  • VBO doesn't care about "triggers" or "hooks" in the info array. Commented Dec 2, 2012 at 16:09
-1

Try permitting all hooks, rather than just node actions.

'hooks' => array('any' => TRUE),
3
  • 1
    VBO doesn't use the "hooks" key at all. Commented May 11, 2012 at 14:46
  • @Bojan, if you're right, then you probably answer my problem with Deploy's actions not appearing in the actions menu. What is the use of VBO then if it ignores actions added by thrid-party modules? Commented Jun 9, 2012 at 12:08
  • VBO will happily use any action defined through hook_action_info(), it doesn't ignore anything. Sounds like a Deploy bug. Commented Jun 9, 2012 at 22:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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