如何在自定义窗体上创建drupal批处理操作



我正在学习批处理操作api。我尝试使用一个表单创建一个批处理操作,这是我的hook_form

function batch_form_get_form($form, &$form_state){
  $form = array();
  $form['select'] = array(
    '#title' => 'Select',
    '#type' =>'select',
    '#options' => array(
      'batch1' => 'Batch 1',
      'batch2' => 'Batch 2',
    ),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Submit'
  );
  return $form;
}

这是我的表单提交功能

function batch_form_get_form_submit($form,&$form_state){
  $function = 'batch_process_form';
  $_SESSION['http_request_count'] =0;
  $batch = $function;
  batch_set($batch);
  dsm ($function);
}

这是我在batch_set函数上使用的批处理函数

function batch_process_form(){
for($i=0; $i<10; $i++){
  $operations[] = array('batch_operation_result',array($i));
}
  $title = "Batch Started";
  $init_message = "Initialing Batch";
  $progress_message = "Work in Progress";
  $batch = array(
    'operations' => $operations,
    'title' => $title,
    'init_message' => $init_message,
    'progress_message' => $progress_message,
  );
  return $batch;
}

当我尝试运行批处理时,我得到了以下错误

Fatal error: Unsupported operand types in /home/dina/static/d7/includes/form.inc on line 4396 

在form.inc 第4396行

  $batch_set = $init + $batch_definition + $defaults;

我不知道我错过了什么

我想你错过了一件事。

在您的提交功能中,而不是

$batch=$function;

尝试

$batch=$function();

祝好运

最新更新