如果在 Drupal 7 中选择了子术语,如何自动选择分类法父术语?
我有一个显示为清单的词汇表,其中包含父项和子项术语,例如:
- Parent 1
- 子1.1
- 子1.2
- Parent 2
- Child2.1
- Child2.2
- 子2.3
我的要求是默认禁用父项。如果用户选择任何子术语,则会自动选择父术语。
建议?
I have a vocabulary displayed as checklist that has both parent and child terms like:
- Parent 1
- Child1.1
- Child1.2
- Parent 2
- Child2.1
- Child2.2
- Child2.3
My requirement is to have the parent term disabled by default. In case user selects any of the child term, the parent gets automatically selected.
Suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在保存时修改参考字段的值。如果节点实体使用 hook_node_presave()。
首先获取原始tid &使用taxonomy_term_load() 加载它以获取术语对象,从中获取父ID 并将其替换到参考字段中。
You can modify the value of the reference field on save. If node entity use hook_node_presave().
First get the original tid & load it using taxonomy_term_load() to get term object, get parent id from that and replace it in the reference field.
术语参考树小部件模块提供了一个用于选择术语的漂亮界面,并提供了一个在以下情况下选择父术语的选项:选择孩子。
The Term Reference Tree Widget Module provides a nice interface for selecting terms and gives an options to select the parent term when selecting the child.