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