Drupal Form-API:#field_prefix 不适用于文本字段
我正在尝试在文本字段上实现#field_prefix,以便我可以向表单添加一些额外的 UI。
我有一个模块,我正在其中进行其他类似的覆盖,其功能基本上如下所示:
function modulename_form_alter(&$form, $form_state, $form_id){
if ($form_id == "contenttype_node_form"){
$form['field_contenttype_fieldname'][0]['#prefix'] = 'prefix'; //this line works
$form['field_contenttype_fieldname'][0]['#field_prefix'] = 'field_prefix'; //this line doesn't work
}
这是文档,看起来非常简单: http://api.drupal.org/api/ file/developer/topics/forms_api_reference.html/6#field_prefix
我已重命名我的主题以有效禁用它 - 应该证明我没有任何其他会发生冲突的覆盖。
我缺少什么?
更新: 最终覆盖 theme_form_element 以在 #field_name 满足正确条件时手动插入我的前缀。 感觉很hacky,但text_textfield 根本不支持#field_prefix。
I'm trying to implement #field_prefix on a text field so I can add some extra UI to my form.
I have a module where I'm doing other overrides like this, with a function that basically looks like this:
function modulename_form_alter(&$form, $form_state, $form_id){
if ($form_id == "contenttype_node_form"){
$form['field_contenttype_fieldname'][0]['#prefix'] = 'prefix'; //this line works
$form['field_contenttype_fieldname'][0]['#field_prefix'] = 'field_prefix'; //this line doesn't work
}
Here's the docs, seems pretty straight forward:
http://api.drupal.org/api/file/developer/topics/forms_api_reference.html/6#field_prefix
I've renamed my theme to effectively disable it - should prove I don't have any other overrides hanging around that would conflict.
What am I missing?
Update:
Ended up overriding theme_form_element to insert my prefix manually when the #field_name meets the right condition. Feels hacky, but text_textfield simply doesn't support #field_prefix.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的猜测是,作为 CCK 字段
field_contenttype_fieldname
实际上并不是一个文本字段,而是 CCK 提供的自定义 FormAPI 字段,它就像 一个文本字段,因此它不会消耗field_prefix
属性。尝试从
$form
中print_r()
将该字段移出,看看它的#type
是什么。My guess is that as a CCK field
field_contenttype_fieldname
isn't actually a textfield, but a custom FormAPI field CCK provides that's like a textfield, and as such it doesn't consume thefield_prefix
attribute.Try
print_r()
ing that field out of the$form
and see what its#type
is.