我的hook_views_handlers()没有被调用。我已经尝试过清除缓存,重新安装模块,等等。我添加了watchdog()调用来查看它是否被调用,但它永远不会被调用。
此字段显示计数器使用的代码视图类型与计数器使用的代码视图类型相同:
我可以将该字段添加到视图中,但一旦添加,它就会显示为“已损坏/缺失”
所有这3个文件都位于funwithviews模块目录的根目录中。下面是相关的代码。
有没有什么地方看起来不对劲?
它存在于: funwithviews.module
/**
* Implements hook_views_api().
*/
function funwithviews_views_api() {
return array(
'api' => 3.0
);
}它存在于: 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',
),
),
);
}它存在于: funwithviews_handler_field_fwv_counter.inc
class funwithviews_handler_field_fwv_counter extends views_handler_field {发布于 2012-02-19 01:18:44
是的,您必须将其添加到您的info文件中,我认为视图本身就说明了这一点:http://drupalcode.org/project/views.git/blob/refs/heads/7.x-3.x:/views.info
发布于 2012-02-19 01:12:56
我是通过在.info文件中定义视图文件来实现这一点的。
files[] = funwithviews.views.inc
files[] = funwithviews_handler_field_fwv_counter.inchook_views_handlers()不再位于视图中。
发布于 2016-01-27 23:39:41
files[] = funwithviews.views.inc
files[] = funwithviews_handler_field_fwv_counter.inc
第一行不是必需的。只有一秒。在Drupal7中,您只能通过Class将文件包含在.info文件中。
文件funwithviews.views.inc将通过hook_views_api自动包含在您的.module文件中。
https://stackoverflow.com/questions/9340017
复制相似问题