1

I am trying to build a views filter and after a lot of digging into the views-workflow, I think I might have understood the basics. I used a lot of resources 1 2 3 4 and of course doc.logrus.com, but now Views tells me that my handler is broken.

If there is anybody outhere that can help me get my filter-handler working, I would be in a huge debt!

Right now I have the following three files:

ds_regions.module

function ds_regions_views_api(){
  return array(
    'api' => 3,
    'path' => drupal_get_path('module','ds_regions')
  );
}

ds_regions.views.inc

<?php 
function ds_regions_views_handlers() {
  return array(
    'info' => array(
    'path' => drupal_get_path('module','ds_regions'),
  ),
  'handlers' => array(
    'ds_regions_handler_filter_view' => array (
      'parent' => 'views_handler_filter',
      ),
    ),
  );
}

function ds_regions_views_data(){
  $data=array();
  $data['node']['ds_regions_filter']=array(
    'title' => t('ds regions view filter'),
    'help' => t('Filters the nodes by region'),
    'filter' => array(
      'handler' => 'ds_regions_handler_filter_view',
    ),
  );
  $data['field_data_field_verein']['table']['join']['node']=array(
    'left_field' => 'nid',
    'field' => 'field_verein_tid',
  );
  $data['ds_vereine']['table']['join']['node']=array(
    'left_field' => 'field_verein_tid',
    'left_table' => 'field_data_field_verein',
    'field' => 'tid',
  );
  return $data;
}
?>

ds_regions_handler_filter_view.inc

<?php
class ds_regions_handler_filter_view extends views_handler_filter{
  function admin_summary(){}
  function option_definition(){
    $options = parent::option_definition();
    $options['misc'] = array('default' => '1');
    return $options;
  }
  function value_form(&$form, &$form_state) {
    $form['custom_filter']  = array(
      '#type' => 'textfield'
    );
  }
  function options_form(){}
  function operator_form(){}
  function query(){
  $table = $this->ensure_my_table();
  $this->query->ensure_table('ds_vereine',$this->relationship);
  $this->query->add_where($this->options['group'],"ds_vereine.plz IN (SELECT ds_plz_distance.plz_first FROM `ds_plz_distance` WHERE ds_plz_distance.distance < 20 AND ds_plz_distance.plz_first=ds_vereine.plz) OR ds_vereine.plz IN (SELECT ds_plz_distance.plz_second FROM `ds_plz_distance` WHERE ds_plz_distance.distance < 20 AND ds_plz_distance.plz_second=ds_vereine.plz) OR ds_vereine.plz IN (SELECT ds_plz_ort.plz FROM `ds_plz_ort` ort WHERE ds_plz_ort.kreis=306)");
  }
}
?>
1

You are looking at Drupal 6 documentation.

You don't need hook_views_handlers() anymore in D7. Instead, you add the file(s) that contains your views handler(s) to your .info file like this:

files[]=ds_regions_handler_filter_view.inc
  • that actually resolves my issue! one more thing, if I may, my where clause seems to be incorrect, but I do not seem to find the cure. examiner.com/open-source-in-national/… does the same, I guess, but it's not working for me? Thanks anyway! – alex Mar 1 '12 at 22:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.