I have a content type that needs a 'category' field; this can both be a taxonomy vocabulary or a text field (with the select widget), it doesn't really matter. (I won't have more then 5-6 voices at once.)

However, those voices may change over time, and normal users should be able to choose only few values when creating a new node.

What is the best practice to achieve this?

My idea is to use a taxonomy vocabulary, where only administrators can insert new voices, but I will need some kind of attribute (e.g., a boolean) that I can use in a module in order to filter them in hook_form_alter(). Could this be a Drupal-ish way to achieve that?

3 Answers 3


You could use a Node Reference field where your 'Voices' are nodes that only administrators can make, that way you can restrict the maximum number of 'Voices' allowed in the Node Reference field settings, and you could turn 'Voices' off by un-publishing them, or if you need the boolean value for the Node output you could just add a Checkbox text field on the 'Voices' node and use the Custom Formatters module to render the Node Reference field out as you wish.

  • mongolito404 answer seem to be the correct answer to my original question, but the idea to use nodes could be (in my situation) the solution, becose every 'voice' would need a page where it is explained. Thanks for the idea!
    – Strae
    Mar 22, 2011 at 8:39

I would use taxonomy terms for voices. From there I see two options to store their enabled/disabled states. You can either add a custom table (using the Schema API) with tid and state columns. Or, if you only have a few enabled voices, use a configuration variable (variable_get & cie.). In the later case, adding a configuration page/form to let administrator select the enabled voice is easy with system_settings_form. You can also alter the taxonomy_form_term form to add a state form field and custom submit handler to terms from your voice vocabulary.

Once you have the enabled/disabled state of voices stored, you can use hook_form_alter to alter the taxonomy form field and restricts its allowed value. You will have to make a decision on what to do when editing an existing node using a currently disabled voice. Either allow it to keep that voices or force it to use an enabled one.


Each term in a vocabulary has a 'weight field' to allow for custom sorting. That could allow you to set a specific order of terms. Are you sure you need the boolean? I assume it is to activate & deactivate a voice from showing in the list? You can just delete the term, but that would orphan the term on the nodes that used it.

You may be better off with a 'computed field' that is fixed once the node is published. http://drupal.org/project/computed_field

Allowing admins to edit taxonomies is probably safer than allowing them to edit a CCK select list.

  • I sould never have orphans, nodes created with 'old' voices have to remain invariate for historycal purpose. I cant have the weight to set what voices are availables, is not user-friendly, i must have a boolean "avaialble yes/not" field.
    – Strae
    Mar 22, 2011 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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