在 Drupal 中对表单进行主题化,该表单必须是实体内容的一部分
我的模块(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 标签和主题。我该怎么做?
谢谢 :-)
I've a form in my module (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;
}
I've used the hook_entity_view hook to display this form under all drupal entities that are displayed.
function mymodule_entity_view($entity, $type, $view_mode, $langcode) {
$entity->content['myadditionalfield'] = mymodule_form();
}
When showing this form, drupal adds a DIV tag to the mytext (password field) by itself. I want to override this and provide my own DIV tags and theme to this form. How do I do it?
Thanks :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我进一步研究这个问题来解决它。问题就解决了。我更改了上面的代码...
每当呈现文本字段或密码字段时,问题就会不断出现。我检查了系统元素信息函数(elements_info 挂钩)中的类型数组,发现文本字段和密码字段带有 #theme-wrapper 的默认值。我试图通过这种方式覆盖它......
并且它有效。它不会生成任何额外的部门标签...:-)
I worked further on this question to solve it. And the problem got solved. I changed the above code...
And the problem kept creeping up whenever a textfield or a password field was rendered. I checked the type array in systems elements info function (a elements_info hook) and found that textfield and password fields come with a default value for the #theme-wrapper. I tried to override it by this way...
and It worked. Its not generating any additional division tags... :-)