You are here

function content_taxonomy_facets_cck_facets_collect in Content Taxonomy 5

Implementation of hook_cck_facets_collect().

File

./content_taxonomy_facets.module, line 15

Code

function content_taxonomy_facets_cck_facets_collect(&$facets, $field, $domain, $env_id, $arg = NULL) {
  if ($field['type'] == 'content_taxonomy') {
    switch ($domain) {
      case 'all':
        $facets[] = new cck_facet($field);
        break;
      case 'text':

        // Scan the given search text for a '{field_name}:{value}'
        // token, and create facets from it.
        if ($tid = search_query_extract($arg, $field['field_name'])) {
          if (is_numeric($tid)) {

            // Create an active facet with the value found in the search text.
            $category = new cck_facet_category($field, $tid);
            $facets[] = new cck_facet($field, array(
              $category,
            ));
          }

          // Remove the parsed text
          $arg = search_query_insert($arg, $field['field_name']);
        }
        break;
      case 'node':
        if (isset($arg->{$field['field_name']}) && is_array($arg->{$field['field_name']})) {

          // Iterate through the field's multiple values.
          foreach ($arg->{$field['field_name']} as $item) {
            $value = array_shift($item);
            if (is_numeric($value)) {
              $category = new cck_facet_category($field, $value);
              $facets[] = new cck_facet($field, array(
                $category,
              ));
            }
          }
        }
        break;
    }
  }
  return $arg;
}