【发布时间】:2016-05-13 13:24:51
【问题描述】:
我正在使用View Bulk Operation 模块对我列出我的内容的自定义视图进行多次删除。
但是我必须检查一个值才能知道我是否接受删除内容...
我已经设法在我的/admin/content 视图上使用hook_form_alter() 进行多项选择,但是当我在我的自定义视图上执行此操作时它不会触发...
我尝试过其他钩子,例如:
-
hook_views_bulk_operations_form_alter()听起来不错……但它根本不会触发 -
hook_node_delete()可以工作,但我不知道如何在函数中停止删除过程(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() 如何触发?
【问题讨论】: