Tags Vocabularies Without The Pitfalls
on
December 3, 2008
Tags Vocabularies Without The Pitfalls
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;
- 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).
- Give the administer taxonomy permission to this role.
- Edit the vocabulary you want to use for tagging
- Uncheck Tags, check Multiple Select, and save.
- Go to the add terms page for the vocabulary
- 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. - Go to Administer >> Menus >> Navigation >> Add item (
admin/build/menu-customize/navigation/add) - Paste the path you copied earlier into Path field
- 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
- Set Parent item to Navigation >> Create content and save
- Log in as a user with the role you gave permissions to in step 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. - 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.
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.
catch December 3, 2008
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.












