Problem/Motivation

I'm working on a module where I would like to add views support. To access my data structure and let it available to views I need to provide a new handler derived from views_join that provides multiple primary key support.
After providing the required hooks, description data structure and .inc files, I noticed the .inc file for my handler wasn't included.

Code from mymodule.views.inc:

function mymodule_views_data() {

  ...

  $data['mytabledetail']['table']['join'] = array(
    'node' => array(
      'handler' => 'mymodule_views_join_multikey',
      'left_table' => 'mytablemaster',
      'left_field' => 'vid',
      'field' => 'vid',
    ),
  );

  ...

  return $data;
}

function mymodule_views_handlers() {
  return array(
    'info' => array(
      'path' => drupal_get_path('module', 'mymodule'),
    ),
    'handlers' => array(
      'mymodule_views_join_multikey' => array(
        'parent' => 'views_join',
      ),
    ),
  );
}

Code from mymodule_views_join_multikey.inc:

class mymodule_views_join_multikey extends views_join {
  function join($table, &$query) {
    return parent::join($table, $query).' /* CUSTOM HANDLER */';
  }
}

After setting up a new view that uses mytabledetail fields the ' /* CUSTOM HANDLER */' string wasn't appended to the query.

I took a look on how views loads the handlers. In views/includes/handlers.inc in the function views_get_table_join I noticed that this check fails:
if (!empty($h['handler']) && class_exists($h['handler'])) {
cause class_exists($h['handler']) returns false.

Proposed resolution

I didn't investigate how the custom handler .inc file was missing inclusion. The resolution of this issue is to provide inclusion like for filter handlers, for example.

The actual workaround is to place the handler object in the mymodule.views.inc file instead of storing it in its .inc file.

Comments

dawehner’s picture

Mhhh as join aren't really handlers but just classes hook_views_handlers doesn't work for them.

One way for you to fix that could be to put your custom join handler into your .views.inc file, and if this doesn't help even into your .module file, which
for sure works!.

Chris Matthews’s picture

Status: Active » Closed (outdated)

The Drupal 6 branch is no longer supported, please check with the D6LTS project if you need further support. For more information as to why this issue was closed, please see issue #3030347: Plan to clean process issue queue