【问题标题】:Drupal 7 VBO's hook form_alter doesn't triggerDrupal 7 VBO 的钩子 form_alter 不会触发
【发布时间】: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() 如何触发?

【问题讨论】:

    标签: drupal drupal-7 hook


    【解决方案1】:

    我认为 VBO 没有自己的表单更改钩子,因此根本不会调用 hook_views_bulk_operations_form_alter()

    我一直这样做的方式是使用hook_form_alter(),类似于您的解决方案,但检查表单 ID 以仅对我感兴趣的 VBO 表单进行操作。

    理论上你可以在 VBO 表单上添加一个 alter hook,但我认为它会比直接在 hook_form_alter() 中实现要慢。不过,如果您有很多 VBO 表单来修改它可能是值得的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-08
      • 2015-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-08
      相关资源
      最近更新 更多