You are here

function content_taxonomy_activeselect in Content Taxonomy 5

return depending values (--> ajax) see activeselect

1 string reference to 'content_taxonomy_activeselect'
content_taxonomy_activeselect_menu in ./content_taxonomy_activeselect.module
Implementation of hook_menu

File

./content_taxonomy_activeselect.module, line 203
Defines a widget type for content_taxonomy with activeselects

Code

function content_taxonomy_activeselect($source, $targets, $string, $extra = NULL) {
  if (empty($source) || empty($targets) || empty($string)) {
    exit;
  }
  $targets = explode(',', $targets);
  $extras = explode(',', $extra);
  $type = $extras[0];
  $multiple = $extras[1];
  $default_vid = $extras[2];
  for ($i = 2; $i < count($extras); $i++) {
    foreach ($targets as $target) {
      if (strtok($extras[$i], '@') == $target) {
        $default_tids[$target][] = drupal_substr($extras[$i], drupal_strlen($target) + 1);
      }
    }
  }
  $output = array();
  $array = activeselect_explode_values($string);
  foreach ($targets as $target) {
    $options = array();
    foreach ($array as $id => $value) {
      if ($type == 'voc') {
        $terms = taxonomy_get_tree($id);
        $options[0]['value'] = '< whole vocabulary >';
      }
      else {
        $terms = taxonomy_get_children($id);
        $options[0]['value'] = '---';
      }
      foreach ($terms as $term) {
        $options[$term->tid]['value'] = $term->name;
        if (is_array($default_tids[$target]) && in_array($term->tid, $default_tids[$target])) {
          $options[$term->tid]['selected'] = TRUE;
        }
      }
    }
    $output[$target] = array(
      'options' => $options,
      'multiple' => $multiple,
    );
  }
  activeselect_set_header_nocache();
  print drupal_to_js($output);
  exit;
}