Module Description
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:


* 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;
Project Usage
2153
Creation Date
Changed Date
Security Covered
Covered By Security Advisory
Version Available
Production
Module Summary
This module aims to solve the issue of indicating the depth of a taxonomy term, with the ability to automatically calculate and set term depths on save or update, as well as providing better integration with Views.
Data Name
taxonomy_term_depth

OPENAI CHATBOT

OPENAI CHATBOT

14:25:56
Generic Chatbot
Hi, I'm a Drupal module expert powered by OpenAI, answering your questions about the Drupal module ecosystem. How can I be helpful today? Please note that we will log your question.