Rules-based Taxonomy Term Creation in Drupal 7

Submitted by Barrett on Fri, 03/02/2012 - 09:04
Rules-based Taxonomy Term Creation in Drupal 7

This morning, I went looking for a means to automatically create a Taxonomy term when a new node of a given type is published. To my surprise, though, the old Taxonomy action set which appeared in the D6 version of Rules was missing from the D7 version of Rules. A quick search of the Rules issue queue revealed that I wasn't the only one looking for Taxonomy actions. Several more minutes of poking around the interface revealed that the solution is there, it's just obscured in the interface.

action type list

The critical bit of information which I had forgotten is that, in Drupal 7, Taxonomy terms are entities, so the Rules interface expects you to create a new term by selecting the "Create a new entity" action then selecting "Taxonomy term" for the entity type. From there, setup proceeds about as you'd expect until you get to the point of selecting the vocabulary in which the new term should appear. In my case, I wanted to create a term in the Projects vocabulary, so I entered the vocabulary's machine name "project" and promptly got an error.

error message

The problem is that the interface expects the vocabulary's vid which, from what I can see, doesn't appear anywhere in the interface. The interface uses the machine name everywhere. The only place I could find the vid was in the taxonomy_vocabulary table in the database.

So, to my mind, there are two non-trivial usability problems with the interface for creating taxonomy terms in Rules. First, you have to know that Taxonomy types are entities. Now, this probably not an unreasonable expectation. Let's face it, if you don't know that they're entities should you really be poking around in Rules? The counter argument, though, is that entities are an abstraction layer to make things easier to work with. I shouldn't need to have to know that terms are entities, that should be handled under the hood. Frankly, I can go either way on that point but it would make things much more accessible if Taxonomy actions appeared in the action list directly. Really, all it would be would be short-cuts to the interface elements and functionality which already exist under the "Create a new entity" tree.

The second point seems like much more of an issue to me. If the interface demands information from me, I should be able to find that information in the interface. If Rules is going to require a vid, then I expect that value to appear somewhere on the vocabulary page. If it doesn't (as is currently the case), then I expect Rules to accept the machine name which does appear on the vocabulary page.

vocabulary edit screen


Barrett Fri, 03/02/2012 - 09:04