Drupal 7:为每个节点创建一个分类术语并使用节点标题作为术语名称
无论如何,是否可以通过使用规则或某些自定义代码来做到这一点? 我确实尝试使用规则,但找不到添加新术语并将名称设置为节点标题的方法,因为 [node:title] 令牌不可用。
我知道使用 NAT 模块是可能的,但是如果您添加术语参考字段使用相同的分类词汇,这破坏了我想做的事情的整个目的。
Is there anyway of doing this by using rules or by some custom code?
I did try using rules but I can't find a way of adding a new term and set the name as the node title because the [node:title] token is not avilable.
I know this is possible using the NAT module but the way this module changes the taxonomy terms hierarchy if you add a term reference field that uses the same taxonomy vocabulary which ruins the whole purpose of what I am trying to do.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
乍一看,我有两个建议:
在 Drupal 7 中,您可以为每个词汇表创建字段,因此也许您创建“
一个带有字段的术语
”而不是更有趣每次创建“一个带有字段的节点 + 一个术语
”?否则,任何需要通过其匹配的分类术语引用您的节点的实体都可以直接引用该节点(使用“
Node Reference
”字段),这样您就不需要维护与节点列表并行的分隔词汇表。但如果您仍然想为每个节点创建一个术语,那么您应该使用 Haza 提到的钩子。
At first glance, I would have two suggestions:
In Drupal 7, you can create fields per vocabulary, so perhaps it would be more interesting for you to create "
one term with fields
" instead of creating "one node with fields + one term
" each time ?Otherwise, whatever entity needs to reference your node thru its matching taxonomy term could directly reference the node instead (using a "
Node Reference
" field), that way you wouldn't need to maintain a separated vocabulary in parallel of your list of nodes.But if you still want to create one term per node, then you should use the hooks that Haza mentioned.
使用 hook_node_insert() 您可以在保存节点时添加一些操作。
只要您在执行此步骤时拥有所有节点信息,那么同时创建分类术语就没有真正的困难。
请注意,还有一个 hook_node_update() 函数。
Using hook_node_insert() you are able to add some operations when a node is saved.
As long as you have all the node informations when you are at this step, there no real difficulties to create a taxonomy term at the same time.
Be aware that there is also a hook_node_update() function.
这并不像上面的帖子让您相信的那么简单。如果您想要仅保持术语名称和节点标题同步的功能,请尝试 NAT 模块。尽管我必须编写自己的模块来完成您的操作要求。
如果您使用分类法来构建所有内容的图形结构(类似于 RDF),则使用节点字段构建术语是行不通的。当然,您可以为您想要的每种内容类型创建一个新的词汇包,但是像这样的函数
是用单个词汇表和不同的指向系统编写的(引用与术语中调用的任何关系字段 - 集父级) )
尽管核心分类功能在词汇间关系方面受到限制,但它仍然比 og 或参考文献所具有的要好得多。关系模块是理想的,但到目前为止,社区支持几乎没有。在我看来,关系应该进入核心。
It's not quite as simple as the above posts would have you believe. If you want functionality that just keeps a term name and node title in sync, try the NAT module. Although I had to write my own module to do what your op is asking.
Building out a term with what would be the node fields doesn't work if you're using taxonomy to build a graphical structure of all your content (kind of like RDF). Sure, you could have a new vocabulary bundle for every content type you want, but functions like
were written with single vocabularies in mind and with a different pointing system (references vs whatever the relationships field is called in a term - sets parent(s))
As limited as core taxonomy functions are with respect to inter-vocabulary relationships, it's still a heck of a lot better than what og or references have. Relation module is ideal but there's almost nada in the way of community support so far. Relation should go into core imo.