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。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值