Reputation: 13321
My hook_views_handlers() is not getting called. I've tried clearing cache, re-installing the module, etc... I've added watchdog() calls to see if it gets called, and it never does.
This field exposes a counter with the same type of code views counter uses:
I can add the field to the view, but once I add it, it just shows as "Broken/Missing"
All 3 of these files are in the root of the funwithviews module directory. Here is the relavent code.
Does anything look out of place?
This exists in: funwithviews.module
/**
* Implements hook_views_api().
*/
function funwithviews_views_api() {
return array(
'api' => 3.0
);
}
This exists in: funwithviews.views.inc
/**
* Implementation of hook_views_data()
*/
function funwithviews_views_data() {
$data['fwv']['table']['group'] = t('FunSpace');
$data['fwv']['table']['join'] = array(
'#global' => array(),
);
$data['fwv']['counter'] = array(
'title' => t('Fun counter'),
'help' => t('This counter is more fun than the other one.'),
'field' => array(
'handler' => 'funwithviews_handler_field_fwv_counter',
),
);
return $data;
}
/**
* Implements of hook_views_handlers().
*/
function funwithviews_views_handlers() {
return array(
'info' => array(
'path' => drupal_get_path('module', 'funwithviews'),
),
'handlers' => array(
'funwithviews_handler_field_fwv_counter' => array(
'parent' => 'views_handler_field',
),
),
);
}
This exists in: funwithviews_handler_field_fwv_counter.inc
class funwithviews_handler_field_fwv_counter extends views_handler_field {
Upvotes: 2
Views: 1254
Reputation: 111
files[] = funwithviews.views.inc
files[] = funwithviews_handler_field_fwv_counter.inc
First line is not necessary. Only second. In Drupal 7 You may include files in .info
file only with Class.
File funwithviews.views.inc
will be automatically included through hook_views_api
in Your .module
file.
Upvotes: 1
Reputation: 8710
It's work but if you put a die('something');
in hook_handlers it not called.this a tricky way and is not a standard way.
/**
* Implements of hook_views_handlers().
*/
function funwithviews_views_handlers() {
die('something');
return array(
'info' => array(
'path' => drupal_get_path('module', 'funwithviews'),
),
'handlers' => array(
'funwithviews_handler_field_fwv_counter' => array(
'parent' => 'views_handler_field',
),
),
);
}
maybe because your module name (end with views) ,drupal hook parser not detect it correctly.
I exactlly have this problem.(my module name ended with views my_module
).
Upvotes: 0
Reputation: 13321
I got this working by defining the views files in my .info file.
files[] = funwithviews.views.inc
files[] = funwithviews_handler_field_fwv_counter.inc
hook_views_handlers() is no longer in Views.
Upvotes: 2
Reputation: 239
Yes you have to add it to your info file i think as demonstrated by views itself: http://drupalcode.org/project/views.git/blob/refs/heads/7.x-3.x:/views.info
Upvotes: 3