Taxonomy data structure

Taxonomies are used to tag content to organize it into categories or hierarchies. A Vocabulary is a collection of Taxonomy terms.

The core Taxonomy module defines Vocabulary as a config entity bundle, which is the same as NodeType.

Term is an editorial content entity, same as Node.

Term has a vid field that references it's Vocabulary.

Term has a parent field for referencing other parents.

Term has a weight field for determining the order among siblings.

These are all the fields needed to structure a taxonomy. When you move items around in the taxonomy interface and save, the parent and weight fields are adjusted to update the changes.

Content has fields that references the taxonomy terms to add them to the category. One common thing we can do now is provide a list of other content in the same category.

The taxonomy term page uses a view to list content tagged with the term. This uses the taxonomy_index table to quickly fetch the list:

LEFT JOIN {taxonomy_index} "taxonomy_index" ON node_field_data.nid = taxonomy_index.nid
WHERE "taxonomy_index"."status" = '1'

Other views plugins will use the taxonomy_index table.

taxonomy_node_insert() and taxonomy_node_update fires on node creation and save, and calls taxonomy_build_node_index($node), which updates the node in the table.

This is how Drupal stores the taxonomy in the system. This structure is fairly simple but allows the flexibility required for organizing most content. The most complex part the hierarchical taxonomy config form that lets you drag and drop to change the structure. This can be tricky to get right, so it's nice to have a system like Drupal that already does it for you.

Tags
Taxonomy