1

我的模块(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 会自行将 DIV 标记添加到 mytext(密码字段)。我想覆盖它并为此表单提供我自己的 DIV 标签和主题。我该怎么做?

谢谢 :-)

4

1 回答 1

0

我进一步研究了这个问题以解决它。问题得到了解决。我改变了上面的代码......

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;
}

每当呈现文本字段或密码字段时,问题就会不断蔓延。我检查了系统元素信息函数(elements_info 挂钩)中的类型数组,发现文本字段和密码字段带有#theme-wrapper 的默认值。我试图用这种方式覆盖它......

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

它奏效了。它不会生成任何额外的部门标签... :-)

于 2011-06-21T14:22:24.620 回答