如何为“段落”小部件字段生成新的空表单元素?

时间:2018-10-27 20:11:27

标签: drupal drupal-7 paragraph

根据SKU字段的选择,我需要在段落小部件中添加一个新元素。如何才能做到这一点?我在SKU字段上挂起了Ajax处理程序,并在每次更改SKU时都重新构建了表单。我尝试通过下面的代码生成一个元素,但这不能正常工作:

    // In hook_form_alter...
    $paragraph = new ParagraphsItemEntity([
      'field_name' => 'field_matrix_view_line_format',
      'bundle' => 'line_row',
    ]);

    $paragraph->is_new = TRUE;
    $paragraph_form = [];
    $paragraph_form_state = [];

    field_attach_form('paragraphs_item', $paragraph, $paragraph_form, $paragraph_form_state);

    $form['field_matrix_view_line_format']['und'][0] = $paragraph_form;

enter image description here

0 个答案:

没有答案