December 2009

Programmatically create vocabulary

Imagine a situation in which you are developing a custom module and would like to create a vocabulary when ever your module is installed on a Drupal site. You can instruct the user to create a vocabulary with desired name and settings but the best approach to this situation is to create a vocabulary from the code and populate it with terms right within the module you have developed. This will reduce dependency and the user need not have to configure it manually. This will result in more use of module.

To create a vocabulary using the code you need the function taxonomy_save_vocabulary($vocabullary)
where $vocabullary is an associative array containing information about the vocabulary being created.
The $vocabulary would be:
<?php
$vocabulary = array(

Syndicate content

Recent comments

toolbar powered by www.mit3xxx.de