You are here

function farm_constraint_taxonomy_term_children in farmOS 7

Find taxonomy term child constraints.

Parameters

$tid: The taxonomy term ID.

Return value

array Returns an array of references to the entity.

1 call to farm_constraint_taxonomy_term_children()
farm_constraint_farm_constraint in modules/farm/farm_constraint/farm_constraint.farm_constraint.inc
Implements hook_farm_constraint().

File

modules/farm/farm_constraint/farm_constraint.farm_constraint.inc, line 145
Farm constraint hook implementations.

Code

function farm_constraint_taxonomy_term_children($tid) {

  // Start an empty children array.
  $children = array();

  // Query the term hierarchy table to find child terms.
  $result = db_query('SELECT tid FROM {taxonomy_term_hierarchy} WHERE parent = :id', array(
    ':id' => $tid,
  ));

  // Iterate through the results and add the reference to the array.
  foreach ($result as $row) {
    if (!empty($row)) {
      $children[] = array(
        'constraint' => 'taxonomy_term_child',
        'entity_type' => 'taxonomy_term',
        'entity_id' => $row->tid,
      );
    }
  }

  // Return the children array.
  return $children;
}