You are here

content_taxonomy_facets.module in Content Taxonomy 5

File

content_taxonomy_facets.module
View source
<?php

/**
 * @file
 * Exposes Content Taxonomy fields as facets.
 */
require_once './' . drupal_get_path('module', 'cck_facets') . '/cck_facets.inc';

/**
 * Implementation of hook_cck_facets_collect().
 */
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;
}

Functions

Namesort descending Description
content_taxonomy_facets_cck_facets_collect Implementation of hook_cck_facets_collect().