The Features module makes it very easy to manage taxonomy vocabularies. Managing taxonomy terms, however, is a bit complicated.
That is mainly because terms are considered content. Therefore, one would not wish to manage terms in a feature any more than he or she would manage nodes.
If that were the case, then there is always the uuid_features module (see link under “Resources”).
Another method would be to export terms to a CSV file. That would allow the developer to easily import terms after each site installation.
Here is how we do it:
Our addition here is the “data” directory. That is where we keep CSV, XML or JSON files that need to be imported into the site in order to build a basic instance of the site. Inside the scripts directory, we would have a script called site-install.sh with commands like these:
And how great would it be to have one more drush command to import taxonomy terms? Here is how:
There is a nice module called Taxonomy CSV import/export. It is a little quirky, but it gets the job done. The current stable version of the module (7.x-5.10) does not appear to work well with Drush 6.2. And that seems to be due to a patch applied to it for compatibility with an earlier version of Drush. The patch calls drush_get_merged_options() and that adds options that the module later complains about. Here is a snippet of the culprit with our debugging lines:
The quickest work around is to download the dev version of the module:
Here is a command to export terms to a csv file.
You will notice that the output is a bit verbose. Another issue is that it creates a redundant out-file in the public files directory even though we provided a destination as an argument.
Here is a command to import the terms:
Even though the destination vocabulary option is called “–vocabulary_id”, you will notice that it also accepts a vocabulary name.
Once the terms are imported, we can verify with a quick db query:
You can take a look at all of the available options by issuing the following command:
Or, just browse to /admin/help/taxonomy_csv for an extended discussion on the topic.
BLEN Corp is a small, minority and veteran-owned information technology firm located in Washington D.C. Since 2004, we have been ahead of the curve in early adaption and implementation of cutting edge technologies including web and mobile development, service-oriented architecture, and other innovative web based solutions. Look at some of our projects.
655 New York Ave NW
Washington, DC 20001