6

I have a situation where I would like to add a field to a vocabulary itself. In other words, I need an editable field on the form that normally appears at /admin/structure/taxonomy/my_vocabulary/edit and not a field that appears each term in the vocabulary. Unfortunately, the description column in {taxonomy_vocabulary} is too limited for what I need.

What is the best way to go about this? If possible I would like to avoid making a custom module with a custom table, form-alters for the vocabulary edit page, etc.

Thanks.

6

So the basic problem is that a vocabulary is not fieldable. In theory this is easy to fix, but I don't know if they lack this functionality because it would cause technical difficulties, or to avoid confusion users.

To make a vocabulary fieldable, implement hook_entity_info_alter:

function hook_entity_info_alter(&$entity_info) {
  $entity_info['taxonomy_vocabulary']['fieldable'] = TRUE;
}
  • 1
    +1 That's a great answer...looking at the controller classes (TaxonomyVocabularyController and TaxonomyTermController) there's not much difference so nothing to suggest fields wouldn't work out of the box. – Clive Feb 1 '12 at 16:17
  • If I go with this, I assume I would have to wire up everything to add fields via the UI myself? – mpdonadio Feb 1 '12 at 17:03
  • I'm not sure I understand that question. Obviously you need to "add the field yourself", but it wouldn't need to happen through the UI. You could add field programmatically. – Letharion Feb 1 '12 at 19:50
  • @Letharion, thanks. I'm just trying to make things as simple as possible for an odd request that came in on a project. – mpdonadio Feb 1 '12 at 23:30
6

You can use the Fieldable vocabularies module.

This module exposes the Vocabulary to the field system. It defines a single bundle and a single view mode.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.