Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Taxonomy Term Depth

Security covered Under active development 3,049 sites

This module automatically adds a "depth" property to taxonomy terms, indicating their level within a hierarchy. It updates this depth when terms are saved or moved and includes a tool to calculate depths for existing terms.

This module adds crucial property called "depth" which indicates the term depth with a value 1, 2, 3 and further if needed. It automatically changes taxonomy term depth on save or update. Also there is a batch to automatically calculate and set all term depths if you are installing this on existing project.

To-Do:

  1. Better integration with Views: field, filter, sort

This is now in beta state so it is for code usage only. Please create issues, argue with me, tell your ideas and of course PATCHES ARE WELCOME!

Here is short api documentation of useful functions:

taxonomy_term_depth_get_by_tid($tid, $force = FALSE);

Gets term's depth value in digital representation
$tid is term id which depth needs to be get
$force (optional) when set to TRUE, the depth will be recalculated again using SQL queries and database record will be updated with new value. For example, if you changed its parent using plain SQL update query, you can easily call this function with $force=true and depth value will be updated in database

function taxonomy_term_depth_get_chain($tid, $reveresed = FALSE);

Returns an array containing all parents of this term
$tid is the identifier of term whose parent we need to get
$reversed (optional) if set to TRUE the return array will be reversed

Examples:

  Term level 1 [tid=1]
  --Term level 2 [tid=2]
  ----Term level 3 [tid=3]

> echo taxonomy_term_depth_get_by_tid(3);
> 3

> echo taxonomy_term_depth_get_by_tid(1):
> 1


> print_r(taxonomy_term_depth_get_parents(1));
> array()

> print_r(taxonomy_term_depth_get_parents(3));
> array(2, 1)

> print_r(taxonomy_term_depth_get_full_chain(1));
> array(1, 2, 3)

> print_r(taxonomy_term_depth_get_full_chain(1, TRUE));
> array(3, 2, 1)

Drupal 8 Highlights

Looks like the name depth have conflicts if using it as field name, so there is property depth_level

// To get level from Term object use field depth_level
$depth = $entity->depth_level->first() ? $entity->depth_level->first()->value : NULL;
Drupal 10–11

Ask your assistant about Taxonomy Term Depth

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

Depends on

Dependencies of the latest stable release

  • taxonomy Drupal core

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
8
Tracked since
May 2023
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 6
Maintenance
Dormant

Release Timeline

Releases

Version Type Core PHP Release date
3.0.1 Stable 10–11 Apr 2, 2025
3.0.1-rc1 Pre-release 10–11 Mar 19, 2025
3.0.0 Stable 10–11 Mar 5, 2025
3.0.0-rc1 Pre-release 10–11 Feb 19, 2025
3.0.0-beta1 Pre-release 10–11 Feb 5, 2025
3.0.x-dev Dev 10–11 Jan 11, 2025
8.x-2.6 Stable 8–10 May 23, 2023
8.x-2.6-rc1 Pre-release 8–10 May 9, 2023