2016-05-13 52 views
0

我正在使用View Bulk Operation模塊對我的自定義視圖進行多重刪除,並在其中列出了我的內容。Drupal 7 VBO的鉤子form_alter不會觸發

但我要檢查一個值就知道我是否接受刪除內容或不... 我已經成功與多重選擇這樣做對我的看法/admin/contenthook_form_alter()但它不會觸發我這樣做對我的自定義視圖時...

我試過其他類似的鉤子:

  • hook_views_bulk_operations_form_alter()這聽起來不錯......不過,這並不在所有
  • hook_node_delete()觸發可以有工作,但我有n Ø知道如何停止刪除過程中的函數時(exit;break;只是拋出一個錯誤,我不知道爲什麼)

我這正常工作與「內容頁」的hook_form_later代碼:

function MODULE-NAME_form_alter(&$form, &$form_state, $form_id) { 
    foreach($form['nodes'] as $pnode) 
    { 
    if(is_array($pnode)) 
    { 
     if(!isDeletable($pnode['#value'])) // my function which says if we can delete the content 
     { 
      $n = node_load($pnode['#value']); 
      $status = isset($n->workbench_moderation['current']->state) ? $n->workbench_moderation['current']->state : false; 
      $string = "This content won't be deleted : ".substr($pnode['#suffix'],0,-6); // substr to cut off the '</li>' ! 
      drupal_set_message(t($string), 'warning'); 

      unset($form['nodes'][''.$pnode['#value']]); // get the content off the form (my way to say that the content shouldn't be deleted) 
     } 
    } 
    } 
} 

hook_views_bulk_operations_form_alter()如何觸發?

回答

0

我不認爲VBO有自己的形式改變掛鉤,所以hook_views_bulk_operations_form_alter()根本不被調用。

的方式我一直在做的是通過使用hook_form_alter(),類似於您的解決方案,但與形式ID的檢查,只作用於VBO形式我感興趣的

理論上你可以在VBO表單上添加一個修改鉤子,但我認爲這會比直接在hook_form_alter()中執行更慢。如果你有很多VBO表單來修改它,可能是值得的。