By snoble on
Would anybody be open to incorporating a patch that would create separate functions in taxonomy.module for the database operations that need to occur when taxonomy_save_term is called. It seems to be currently designed so that the only way a term can be created is through a form (the parameter is even called $form_values). While this does still allow other modules to create terms it makes for unclean code. Plus taxonomy_save_term cannot return a new term id when a term is created.
I will certainly create the patch myself if someone is interested in incorporating it (accepting that they may change their mind later when they see the patch). Otherwise, I will not bother.
Thanks,
Steven
Comments
Needed!
Hi,
we have just ran across this when we need to create a new term programatically; unless core devs have better solutions, I would vote your patch.
-Tobias
why?
What's the problem here?
taxonomy_save_term() primarily expects form_values, but that's just a convention that allows you to pass it an array of values. A term definition.
I don't see what's unclean about that code... The tid does come back, in the term passed by reference.
And more to the point, the fact that it takes care of the difference between updates and inserts internally is a benefit of the API. Abstracting the database calls into fragments would surely put the onus of extra logic back into your code, which is probably inappropriate, and more fragile. Surely this should be looked at as an atomic action that the API hides the internals of?
You may get some inspiration by inspecting the way taxonomy_xml handles this.
.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/
.dan. is the New Zealand Drupal Developer working on Government Web Standards