By mb2449 on
Ok, I am been writing my own module for a little bit now, and I am now getting into views. What I am trying to do create a custom filter in views. Basically I will have a drop down with 2 options, and that works fine... but I am unsure of how to actually apply the changes to the view. Like when I select the one option, instead of showing my all the matching hits, it doesnt show me any hits. Here is my code:
// $Id: content_handler_filter_many_to_one.inc,v 1.1.2.5 2009/08/14 19:15:10 markuspetrux Exp $
/**
* @file
* The subclass simply adds properties,
* for field-specific subclasses to use if they need to.
*/
class classifieds_views_handler_filter_seller extends views_handler_filter_many_to_one {
var $content_field;
function construct() {
parent::construct();
$this->content_field = content_fields($this->definition['content_field_name']);
$this->additional_fields = $this->definition['additional fields'];
$field = $this->content_field;
$this->value_title = $field['widget']['label'];
}
function get_value_options() {
$this->value_options = $this->allowed_values();
}
// Get allowed values from hook_allowed_values(), if any,
// or from content_allowed_values();
function allowed_values() {
$field = $this->content_field;
$function = $field['module'] .'_allowed_values';
if ($this->value_form_type == 'select') {
// Select elements accept multidimensional arrays to support optgroups.
$options = function_exists($function) ? $function($field) : content_allowed_values($field, FALSE);
// For selects, HTML should be filtered out and entities left unencoded.
// See content_allowed_values / content_filter_xss / filter_xss.
content_allowed_values_filter_html($options);
}
else {
$options = function_exists($function) ? $function($field) : content_allowed_values($field);
}
/* the only thing i added is below */
$options = array(
0 => 'Private Party',
1 => 'Commerical'
);
return (array) $options;
}
}
I borrowed this from the cck module... since it seemed to be the closest fit for what I was trying to do. Can anyone explain whats going on in this code? Even a link to good site, or a reference to a decently commented example... thanks!
Comments
Not really providing an
Not really providing an answer:
I'm also experimenting with custom view filters and find this page very usefull.
Also have a look at the related links on that page.
http://zugec.com/drupal/creating-custom-filters-in-views-2