I needed to write a custom join handler, so I did it the same way I have written other handlers but the file is never included like the other handlers are included.

Are join handlers a special case? or should they work the same as other handlers?

I wrote a views_join_between handler file called it "views_join_between.inc" and put it in the include directory.

I also defined it and it's parent like I do for other handlers in my module.:

/**
 * Implementation of hook_views_handlers()
 */
function dcats_views_views_handlers() {
  return array(
  'info' => array(
    'path' => drupal_get_path('module', 'dcats_views') . '/handlers',
    ),
  'handlers' => array(
    'views_handler_field_formula' => array(
       'parent' => 'views_handler_field',
     ),
    'views_join_between' => array(
       'parent' => 'views_join',
     ),
    'views_handler_field_device_link' => array(
    ...
    ...
    ...
  );
}

Here is my handler in the same folder as my other handlers but never gets included 'includes/views_join_between.inc'

class views_join_between extends views_join {

  /**
   * Build the SQL for the join this object represents.
   */
  function join($table, &$query) {
    $left = $query->get_table_info($this->left_table);
    $output = " $this->type JOIN {" . $this->table . "} $table[alias] ON $left[alias].$this->left_field >= $table[alias].first_$this->between_field AND $left[alias].$this->left_field <= $table[alias].last_$this->between_field";

    return $output;
  }
}

I ended up putting the class definition in my '.module' file and now it works. (since it is in my module file I cannot extend views_join, I just define a new class

class views_join_between {
  /**
   * Construct the views_join object.
   */
  function construct($table = NULL, $left_table = NULL, $left_field = NULL, $field = NULL, $extra = array(), $type = 'LEFT') {
    $this->extra_type = 'AND';
    if (!empty($table)) {
      $this->table = $table;
      $this->left_table = $left_table;
...
...
... 

  /**
   * Build the SQL for the join this object represents.
   */
  function join($table, &$query) {
    $left = $query->get_table_info($this->left_table);
    $output = " $this->type JOIN {" . $this->table . "} $table[alias] ON $left[alias].$this->left_field >= $table[alias].first_$this->field AND $left[alias].$this->left_field <= $table[alias].last_$this->field";

    return $output;
  }


  /**
   * Ensure that input is db safe. We only check strings and ints tho
   * so something that needs floats in their joins needs to do their
   * own type checking.
   */
  function db_safe($input) {
    if (is_array($input)) {
      $output = array();
...
...
...
}

Comments

merlinofchaos’s picture

Status: Active » Closed (won't fix)

Join handlers are not truly handlers used via hook_views_handlers. You just need to stick them in your *.views.inc file and let them be included. or include it manually if you want to use it.