You are here

function shs_json_term_get_children in Simple hierarchical select 7

JSON callback to get the list of children of a term.

Parameters

int $vid: ID of vocabulary the term is associated to.

array $parent: List of parent terms.

array $settings: Additional settings (for example "display node count").

string $field: Name of field requesting the term list (DOM element name).

Return value

array Associative list of child terms.

See also

shs_term_get_children()

1 string reference to 'shs_json_term_get_children'
shs_json_callbacks in ./shs.module
Get a list of supported JSON callbacks.

File

./shs.module, line 954
Provides an additional widget for term fields to create hierarchical selects.

Code

function shs_json_term_get_children($vid, array $parent = array(), array $settings = array(), $field = NULL) {
  $scope = $result = array();
  foreach ($parent as $tid) {
    $scope[] = shs_term_get_children($vid, $tid, $settings);
    if (shs_add_term_access($vid, $tid, $field)) {
      $result[] = array(
        'vid' => $vid,
      );
    }
  }

  // Rewrite result set to preserve original sort of terms through JSON request.
  foreach ($scope as $terms) {
    foreach ($terms as $tid => $label) {
      $result[] = array(
        'tid' => $tid,
        'label' => $label,
        'has_children' => shs_term_has_children($tid, $vid),
      );
    }
  }
  return $result;
}