Drupal:分类法:使词汇对于特定内容类型是可选的

发布于 2024-10-31 04:09:14 字数 541 浏览 5 评论 0原文

我知道我需要沿着 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

末骤雨初歇 2024-11-07 04:09:14

我知道有一个解决方案;)。今天在忙别的事情的时候发现的。

安装 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.

月下凄凉 2024-11-07 04:09:14
define('MY_VOCABULARY', 1);

$form['taxonomy'][MY_VOCABULARY]['#required'] = 0;

它在 drupal 6 中运行良好。您使用什么 drupal 版本?

define('MY_VOCABULARY', 1);

$form['taxonomy'][MY_VOCABULARY]['#required'] = 0;

it's works fine in drupal 6. what drupal version you use ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文