Drupal:分类法:使词汇对于特定内容类型是可选的
我知道我需要沿着 hook_form_alter 的路径走下去,但这似乎并没有让我走得太远,最初:
hook_form_alter(&$form, &$form_state){
drupal_set_message($form['form_id']['#value']);
switch ($form['form_id']['#value']){
case 'partner_node_form':
$form['taxonomy'][1]['#required']=FALSE;
break;
}
}
DSM 输出 partner_node_form
并且当我转到 /node/add 时代码会触发/partner,但是它并不使该字段成为可选字段,并且仍然带有红色星号。
如果我提交表单,它会失败,并指出该字段是必填字段,但现在 DSM 会输出 admin_block_theme_form
,这甚至会阻止我的更改代码运行。
显然,我很迷路,请帮忙!
I understand that I need to go down the path of hook_form_alter, however this doesn't appear to be getting me very far, initially:
hook_form_alter(&$form, &$form_state){
drupal_set_message($form['form_id']['#value']);
switch ($form['form_id']['#value']){
case 'partner_node_form':
$form['taxonomy'][1]['#required']=FALSE;
break;
}
}
DSM outputs partner_node_form
and the code fires when I go to /node/add/partner, however it doesn't make the field optional, and it is still given a red asterisk.
If I submit the form, it fails, stating that the field is required, but now DSM outputs admin_block_theme_form
instead, which is preventing my alter code from even running.
Obviously, I'm quite lost, please help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道有一个解决方案;)。今天在忙别的事情的时候发现的。
安装 content_taxonomy 模块。执行此操作后,您将在所有内容类型中将分类作为 CCK 字段。因此,您可以将其设置为所选内容类型的可选。您可以选择词汇表,而且您可以像任何其他 CCK 字段一样使用它。
I knew that there was a solution to this ;). Found it today when I was working on something else.
Install content_taxonomy module. Once you do this you will have taxonomy as a CCK field in all the content types. Hence you can make it optional for a selected content type. You have an option to select the vocabulary and moreover you can use this like any other CCK field.
它在 drupal 6 中运行良好。您使用什么 drupal 版本?
it's works fine in drupal 6. what drupal version you use ?