Commit 3aa6f39a authored by David Lesieur's avatar David Lesieur

Added specialized class for Node Reference facets.

parent fe36611b
; $Id$
name = Node Reference Facets
description = "Provides facets based on Node Reference fields."
dependencies = content faceted_search cck_facets search
package = Faceted Search
<?php
// $Id$
/**
* @file
* Provides facets based on Node Reference fields.
*/
/**
* Implementation of hook_cck_facets_factory().
*
* @param $type
* Type of object to create, either 'facet' or 'category'.
* @return
* Array of factory functions keyed by field type.
*/
function nodereference_facets_cck_facets_factory($type) {
if ($type == 'category') {
return array('nodereference' => 'nodereference_facets_create_category');
}
}
/**
* Create category for the specified field value.
*/
function nodereference_facets_create_category($field, $value, $count = NULL, $category_path = TRUE) {
$category = new nodereference_facet_category($field, $value, $count);
return $category_path ? array($category) : $category;
}
/**
* A facet category for Node Reference fields.
*/
class nodereference_facet_category extends cck_facet_category {
/**
* Constructor.
*/
function nodereference_facet_category($field, $value, $count = NULL) {
parent::cck_facet_category($field, $value, $count);
}
/**
* Return the label of this category.
*
* @param $html
* TRUE when HTML is allowed in the label, FALSE otherwise. Checking this
* flag allows implementors to provide a rich-text label if desired, and an
* alternate plain text version for cases where HTML cannot be used. The
* implementor is responsible to ensure adequate security filtering.
*/
function get_label($html = FALSE) {
$db_info = content_database_info($this->_field);
reset($db_info['columns']); // Get the first database column. Other columns are ignored!
$column_name = key($db_info['columns']); // Get the column name (required for the formatter).
// Get the label using the 'plain' formatter.
$label = content_format($this->_field['field_name'], array($column_name => $this->_value), 'plain');
// Note: The label is already filtered by the CCK formatter and does not
// need to be checked here.
return $html ? $label : strip_tags($label);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment