function taxonomy_term_depth_get_by_tid in Taxonomy Term Depth 8.2
Same name and namespace in other branches
- 8 taxonomy_term_depth.module \taxonomy_term_depth_get_by_tid()
- 7 taxonomy_term_depth.module \taxonomy_term_depth_get_by_tid()
@todo: Provide description
Parameters
$tid:
bool $force:
Return value
int
5 calls to taxonomy_term_depth_get_by_tid()
- DynamicDepthCalculationTest::testCalculateDepth in tests/
src/ Functional/ DynamicDepthCalculationTest.php - Creates and ensures that a feed is unique, checks source, and deletes feed.
- Manager::processNextItem in src/
QueueManager/ Manager.php - taxonomy_term_depth_batch_callbacks_update_term_depth in ./
taxonomy_term_depth.batch.inc - taxonomy_term_depth_entity_update in ./
taxonomy_term_depth.module - Implements hook_entity_update();
- UpdateDepth::processItem in src/
Plugin/ QueueWorker/ UpdateDepth.php - Works on a single queue item.
File
- ./
taxonomy_term_depth.module, line 24 - Main module file.
Code
function taxonomy_term_depth_get_by_tid($tid, $force = FALSE) {
$cache =& drupal_static('taxonomy_term_depth', []);
$cache_key = $tid;
if ($force || !isset($cache[$cache_key])) {
// Try to get cached value first but only if no need to rebuild
// If force flag is set to TRUE the query won't be executed
if ($force || !($depth = Drupal::database()
->query('SELECT depth_level FROM {taxonomy_term_field_data} WHERE tid=:tid', [
':tid' => $tid,
])
->fetchField())) {
// Calculate value without using caches
$depth = _taxonomy_term_depth_get_nocache($tid);
// And write to database cache
Drupal::database()
->update('taxonomy_term_field_data')
->fields([
'depth_level' => $depth,
])
->condition('tid', $tid)
->execute();
}
$cache[$cache_key] = $depth;
}
return $cache[$cache_key];
}