Drupal 7 Drupal webform以编程方式创建复合组件

Drupal 7 Drupal webform以编程方式创建复合组件,drupal-7,custom-component,composite-component,drupal-webform,Drupal 7,Custom Component,Composite Component,Drupal Webform,我已成功为特定类型的数据创建了自定义webform组件。数据来自不同的部分,因此我需要创建其他但现有的组件类型,这些类型将是自定义组件的子组件。 基本上,我正在尝试以编程方式创建webform组件的组合 我的问题是,所有代码都成功执行了-我得到了创建自定义组件的反馈,我得到的反馈说我的子组件也成功创建了。 但是,子组件不会显示在我的网络表单中。 在创建自定义组件并将其插入数据库时,我正试图通过以下代码创建所有必要的子组件: function my_module_webform_component

我已成功为特定类型的数据创建了自定义webform组件。数据来自不同的部分,因此我需要创建其他但现有的组件类型,这些类型将是自定义组件的子组件。 基本上,我正在尝试以编程方式创建webform组件的组合

我的问题是,所有代码都成功执行了-我得到了创建自定义组件的反馈,我得到的反馈说我的子组件也成功创建了。 但是,子组件不会显示在我的网络表单中。

在创建自定义组件并将其插入数据库时,我正试图通过以下代码创建所有必要的子组件:

function my_module_webform_component_insert($component){
  if($component['type'] == 'my_component'){
    $node = node_load($component['nid']);

    $address_fields = array("my_sub_component1", "my_sub_component2");

    foreach ($address_fields as $key => $address_field) {
        //fetch next available component ID
        $next_id_query = db_select('webform_component')->condition('nid', $component['nid']);
        $next_id_query->addExpression('MAX(cid) + 1', 'cid');
        $next_cid = $next_id_query->execute()->fetchField();

        _create_sub_component($component['nid'], $address_field, $next_cid, $component['cid']);
    }

  }
}
My_create_sub_组件函数定义如下:

function _create_sub_component($nid, $new_component, $cid, $pid){
    $node = node_load($nid);

    $processed_name  = str_replace(' ', '_', strtolower($new_component));
    // Create the webform components array. Not sure if we need all these
    // values, but let's be sure.
    $component = array(
      'cid' => (int)$cid,
      'pid' => 0,#(int)$pid,
      'nid' =>  (int)$node->nid,
      // I don't trust the admin to make a key based on input :)
      'form_key' => $processed_name,
      'name' => $new_component,
      // I want all lines to be numeric type component.
      'type' => 'textfield',
      'value' => '',
      'extra' => array(),
      'mandatory' => '0',
      'weight' => 0,
      'page_num' => 1,
    );

    array_push($node->webform['components'], $component);
    node_save($node);

    drupal_set_message("{$new_component} component successfully created in {$node->title}");
  }
我猜是对node_save的调用导致了问题,但我不知道确切的原因。

明白了

替换:

array_push($node->webform['components'], $component);
node_save($node)
与:

webform_component_insert($component);