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 vo开发者_开发知识库cabulary which ruins the whole purpose of what I am trying to do.
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.
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.
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
taxonomy_get_parents_all()
taxonomy_get_tree()
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.
精彩评论