首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未调用hook_views_handlers

未调用hook_views_handlers
EN

Stack Overflow用户
提问于 2012-02-18 17:15:36
回答 4查看 1.2K关注 0票数 2

我的hook_views_handlers()没有被调用。我已经尝试过清除缓存,重新安装模块,等等。我添加了watchdog()调用来查看它是否被调用,但它永远不会被调用。

此字段显示计数器使用的代码视图类型与计数器使用的代码视图类型相同:

我可以将该字段添加到视图中,但一旦添加,它就会显示为“已损坏/缺失”

所有这3个文件都位于funwithviews模块目录的根目录中。下面是相关的代码。

有没有什么地方看起来不对劲?

它存在于: funwithviews.module

代码语言:javascript
复制
/**
 * Implements hook_views_api().
 */
function funwithviews_views_api() {
  return array(
    'api' => 3.0
  );
}

它存在于: funwithviews.views.inc

代码语言:javascript
复制
/**
 * 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

代码语言:javascript
复制
class funwithviews_handler_field_fwv_counter extends views_handler_field {
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2012-02-19 01:18:44

是的,您必须将其添加到您的info文件中,我认为视图本身就说明了这一点:http://drupalcode.org/project/views.git/blob/refs/heads/7.x-3.x:/views.info

票数 3
EN

Stack Overflow用户

发布于 2012-02-19 01:12:56

我是通过在.info文件中定义视图文件来实现这一点的。

代码语言:javascript
复制
files[] = funwithviews.views.inc
files[] = funwithviews_handler_field_fwv_counter.inc

hook_views_handlers()不再位于视图中。

票数 2
EN

Stack Overflow用户

发布于 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文件中。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9340017

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档