6

How is it possible to automatically add a taxonomy term for a content type?

Is it possible to make the new added terms children of this automatically set term?

I have a content type intended for users, and I would like them to be only able to add terms that are children of a parent term of my wish; in this way, if they choose a term, it will become a child of my default term, but if they don't add a term, then the node will be tagged automatically with my term (the parent term).

7

In Drupal it is possible to associate a vocabulary to a content type: Once you created your vocabulary, and added the taxonomy terms, you go to admin/structure/types, and for the content type to which you want to associate the vocabulary, you click on manage fields; in my example, I am going to add a vocabulary to the Article content type.

In the Add new field column I fill the fields as follows (the value you use for the field name, and to the field title can be what you like better):

screenshot

When you click on Save, you get the following page. (The shown error is just because I am creating a patch for Drupal 7; it's not something you should see.)

screenshot

Select the vocabulary you want to associate with the content type, and click Save field settings. In the next page, you can select the default value for the taxonomy term, which by default is - None -; you can select the one that is automatically set. If the user doesn't change it, it will be the value associated with the node.

screenshot

When a user will create a node of that content type, they will see something similar to what shown in the following screenshot:

screenshot

In my case, I selected Overview as default taxonomy term.

When you create your vocabulary, you can set a taxonomy term that is the parent of all the other taxonomy terms, and select it as default value for the content type.

screenshot

In this case, Golden apple is child of Apple, which is child of Fruits; Kaiser pear is child of Pear, which is child of Fruit.
As side note, the hierarchy of taxonomy terms that are shown in the node edit form is the one defined in the vocabulary you associated with the content type; this means that, if Apple is not child of Fruit in the vocabulary I am using, then it will not be shown as child, in the node edit form. The taxonomy term widget doesn't alter the vocabulary structure.

3

Yes it is.

You can either do this with a custom module that implements hook_form_alter or by using a module that does this for you.

I can suggest looking at http://drupal.org/project/prepopulate - which may give you some clues on how to achieve this

  • thanks , with prepopulate where do I modify the url? – webestdesigns Aug 1 '11 at 11:42

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.