Module Development

Movie Project: Create Taxonomy Terms Programmatically for Drupal 7

This page is archived

We're keeping this page up as a courtesy to folks who may need to refer to old instructions. We don't plan to update this page.

Check and create taxonomy terms programmatically.

Goal

In a custom module, create taxonomy terms and relate them to a node.

Prerequisites

You will need the following knowledge and skills. If you need a review, check out the Additional resources section at the bottom of this page.

  1. Create taxonomy terms programmatically.
  2. Associate taxonomy terms with a node programmatically.

Tasks

Write conditional logic to meet the following requirements:

  • If a taxonomy term already exists, get the term ID.
  • If the taxonomy term does not exist, create it and return the term ID.

Populate the Genre field with the relevant terms from the data object you retrieved from The Movie DB API in the previous lesson.

Recap

  • Taxonomy terms can be created programmatically.
  • Terms are associated with nodes via a term ID.

Further your understanding

Additional resources

Creative Commons License

Drupal Training Resources by Damian Robinson are licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Based on a work at http://www.damianrobinson.co.uk.

Hands-On Exercises: Movie Project