主题化Drupal中的表单,该表单必须是实体的一部分';s内容


Theming a form in Drupal which has to be a part of an Entity's Content

我的模块(mymodule)中有一个表单。。。

function mymodule_form()
{
   $form['mytext'] = array(
     '#title' => 'Password',
     '#type' => 'password',
     '#size' => 10,
   );
   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => 'Cool!',
   );
   $form['cool_submit'] = array(
     '#type' => 'submit',
     '#value' => 'Cool Submit!',
   );
   return $form;
}

我已经使用hook_entity_view钩子在所有显示的drupal实体下显示了这个表单。

function mymodule_entity_view($entity, $type, $view_mode, $langcode) {
  $entity->content['myadditionalfield'] = mymodule_form();
}

当显示此表单时,drupal会自己向mytext(密码字段)添加一个DIV标记。我想覆盖它,并为这个表单提供我自己的DIV标记和主题。我该怎么做?

感谢:-)

我在这个问题上做了进一步的工作来解决它。问题得到了解决。我更改了上面的代码。。。

function mymodule_entity_view($entity, $type, $view_mode, $langcode) {
  $element = array(
    'start' => array(
        '#type' => 'button',
        '#name' => 'start', 
        '#button_type' => 'submit',
    ),
    'my_text' => array(
        '#type' => 'textfield',
        '#size' => 30, 
        '#maxlength' => 50,
    ),
    'my_submit' => array(
        '#type' => 'button',
        '#name' => 'Submit Discussion',
        '#button_type' => 'submit',
    ),
  );
  $entity->content['disc_bar'] = $element;
}

每当呈现文本字段或密码字段时,问题就会不断出现。我检查了systems-elements-info函数(elements_info钩子)中的类型数组,发现textfield和password字段带有#theme包装器的默认值。我试着用这种方式推翻它。。。

'my_text' => array(
        '#type' => 'textfield',
        '#size' => 30, 
        '#maxlength' => 50,
        '#theme-wrapper' => '',
),

它奏效了。它不会生成任何附加的除法标记…:-)