You are here

function shs_term_has_children in Simple hierarchical select 8

Same name and namespace in other branches
  1. 7 shs.module \shs_term_has_children()
  2. 2.0.x shs.module \shs_term_has_children()

Determine whether a term has children.

Parameters

int $tid: Term ID to check existence of children for.

Return value

bool TRUE if the term has any children, FALSE otherwise.

2 calls to shs_term_has_children()
OptionsShsWidget::validateElement in src/Plugin/Field/FieldWidget/OptionsShsWidget.php
Form validation handler for widget elements.
ShsController::getTermData in src/Controller/ShsController.php
Load term data.

File

./shs.module, line 129
Main functions and methods for the "Simple hierarchical select" module.

Code

function shs_term_has_children($tid) {
  $query = Database::getConnection()
    ->select('taxonomy_term_field_data', 't');
  $query
    ->innerJoin('taxonomy_term__parent', 'p', 'p.entity_id = t.tid');
  $query
    ->condition('p.parent_target_id', $tid);
  $query
    ->addTag('term_access');
  return $query
    ->countQuery()
    ->execute()
    ->fetchField() > 0;
}