drupal7 Views Bulk Operations (VBO)

介绍

drupal通常用views制作列表,列表也应该能实现某些操作,例如删除、审批等,并且应该是批量进行的,VBO的存在就是为了实现views批量操作功能。事实上,drupal把操作统称为action,而VBO的原理仅仅是把views与action关联起来。

 

使用步骤(来源于官方)

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.

 

给VBO添加更多的操作

由于VBO的操作实现依赖于action,所以声明新的action就等于为VBO添加新的操作。
假设开发一个delete node的action,mymodule.module代码大致如下:

/**
 * 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。

posted @ 2013-09-18 22:35  猫之良品  阅读(1130)  评论(0编辑  收藏  举报