drupal一般用views制做列表,列表也应该能实现某些操做,例如删除、审批等,而且应该是批量进行的,VBO的存在就是为了实现views批量操做功能。事实上,drupal把操做统称为action,而VBO的原理仅仅是把views与action关联起来。node
1. Create a View.
2. Add a "Bulk operations" field if available
3. Configure the field. There's a "Views Bulk Operations" fieldset where the actions visible to the user are selected.
4. Go to the View page. VBO functionality should be present.spa
因为VBO的操做实现依赖于action,因此声明新的action就等于为VBO添加新的操做。
假设开发一个delete node的action,mymodule.module代码大体以下:code
/** * Implementation of hook_action_info(). */ function mymodule_action_info() { return array( 'mymodule_node_delete_action' => array( 'label' => t('Delete node'), 'type' => 'node', // 限定的内容类型 'aggregate' => TRUE, // 若是为TRUE,即为批量操做 'configurable' => FALSE, 'triggers' => array('any'), // 触发器限定 ), ); } /** * Implementation of a Drupal action. * Passes selected ids as arguments to a view. */ function mymodule_node_delete_action($entities, $context = array()) { $nids = array_keys($entities); node_delete_multiple($nids); }
而后在views中的"Bulk operations" field就能够看到delete node这个action。blog