Tags Vocabularies Without The Pitfalls

Submitted by Bevan Rudge on December 3, 2008 - 1:10am

Drupal's tagging vocabularies are really useful when webmasters and admins can not anticipate what categories or terms content authors and editors are going to need. The pitfall however, is that it is too easy for content editors to make a mess of the vocabulary by creating duplicate terms that are spelled wrong, similar to or synonymous of existing terms. And a "dirty" vocabulary such as this can be rather difficult to clean up and can be a real problem if content needs to be structured.

The alternative is to create a fixed vocabulary which can only have terms added through the taxonomy admin UI. This avoids building a messy vocabulary, but does away all of the advantages of a folksonomy, or tags vocabulary.

I recently learned a technique that offers most of the best parts of both worlds. Here's the recipe;

  1. Determine which existing role/s can edit content, should be able to add terms to the vocabulary, and are sufficiently trusted (more detail later – read on for now).
  2. Give the administer taxonomy permission to this role.
  3. Edit the vocabulary you want to use for tagging
  4. Uncheck Tags, check Multiple Select, and save.
  5. Go to the add terms page for the vocabulary
  6. copy the part in the URL that is similar to admin/content/taxonomy/123/add/term. 123 will be different for each vocabulary – it is the vocabulary ID.
  7. Go to Administer >> Menus >> Navigation >> Add item (admin/build/menu-customize/navigation/add)
  8. Paste the path you copied earlier into Path field
  9. Set a meaningful Menu link title and Description, such as "Category" and "A category will appear in the list of options for content categories on content edit pages.", respectively
  10. Set Parent item to Navigation >> Create content and save

And your done. To check how this works;

  1. Log in as a user with the role you gave permissions to in step 2
  2. Navigate to Create content (node/add); Your new menu item will show up here next to the links to create content items by type, including the description you just gave it.
  3. Click the link you created; You should see Drupal's Add term form, which is easy, simple and fast enough for content editors to complete and add new terms to your more-controlled-than-tagging vocabulary, but not so simple that they are likely to make a mess of the vocabulary.

For many cases the administer taxonomy permission is probably too permissive – however if the role does not have the access administration pages permission then Administer >> Content >> Taxonomy (admin/content/taxonomy) won't show up in the navigation menu for them, and they likely won't discover the other vocabulary-admin features anyway. Of course you wouldn't want to do this if your content editors are not trusted – but then it's probably not realistic to expect your vocabulary to be kept clean if you don't trust the users adding terms to it anyway!

Alternatively you could create your own menu callback that wraps the add-term form with it's own permission. That's out of scope of this blog, but a good idea for a contrib module.

This was tested on Drupal 6, but will probably work similarly on Drupal 5. It's also entirely possible to put the Add term menu item in another menu more convenient for the content editors.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Submitted by catch on December 3, 2008 - 3:29am.

Depends on the use-case, but hierarchical select module lets you create terms for structured vocabularies direct from the node form (and lots of other nice things) - this saves the administer taxonomy permission, but on the other hand, you can't add term descriptions etc. from the form, same as free-tagging.

And (shameless plug) although there's no UI for the 'add terms' bit yet, I've got a patch against Drupal 7 to split create/edit/delete permissions out per vocabulary - http://drupal.org/node/340652 - actually, we could just change the access callback for admin/content/taxonomy/123/add/term to check for add terms as well as administer. Will update the patch.

Submitted by Bevan Rudge on December 3, 2008 - 6:13pm.

This response came in by email from Matthew:

Adding a menu item pointing directly to the taxonomy/123/add/term form is a nice idea, but it seems to me that it's a bit vulnerable to URL hacking. It only takes a curious user to replace 123 in the above URL with another vocab id, and they could add terms to a different vocabulary.

However, there is a very handy little contrib module - Taxonomy Delegate - that allows the site admin to allow certain roles to edit terms in only the specified vocabularies, but doesn't allow them to modify the vocabulary itself.
http://drupal.org/project/taxonomy_delegate

It seems to me that using taxonomy delegate would add a bit more security to your technique for opening up taxonomy editing. Just a thought...

Submitted by Bevan Rudge on December 3, 2008 - 6:14pm.

Ah yes! I hadn't considered the HS approach to this. This is better for Drupal 5, because Hierarchical Select doesn't yet have a stable release for Drupal 6. I hear a patch is in the queue though.

Submitted by Bevan Rudge on December 3, 2008 - 6:15pm.

It's totally hackable, which is why you would only use this technique if the content editors are relatively well trusted.