Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: OpenID Connect / OAuth client 3.0.0-alpha9 New alpha version released for module openid_connect (3.0.0-alpha9). Usage Milestone: Google Analytics Module google_analytics crossed 1,000 active installs. Release: Timelinr 1.0.1 Minor update available for module timelinr (1.0.1). Release: GraphQL Compose Codegen 1.1.2 Minor update available for module graphql_compose_codegen (1.1.2). Release: Mapy.com 1.1.3 Minor update available for module mapycom (1.1.3). Release: Ckeditor5 entity browser 3.0.3 Minor update available for module ckeditor5_entity_browser (3.0.3). Release: Ckeditor5 entity browser 3.0.1 Minor update available for module ckeditor5_entity_browser (3.0.1). Release: Ckeditor5 entity browser 3.0.2 Minor update available for module ckeditor5_entity_browser (3.0.2). Release: Teamleader Integration 4.0.2 Minor update available for module teamleader (4.0.2). Module Revived: Entityqueue Buttons 1.1.2 Module entityqueue_buttons updated after 8 months of inactivity (1.1.2).

Taxonomy Term Depth

3,129 sites Security covered Drupal 10–11
View on drupal.org

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;

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
6
Tracked since
Jan 2025
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 6
Maintenance
Dormant

Release Timeline

Releases

Version Type Core 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