2012-02-18 61 views
2

我的hook_views_handlers()沒有被調用。我嘗試清除緩存,重新安裝模塊等等。我添加了watchdog()調用來查看它是否被調用,並且它從來沒有。hook_views_handlers沒有被調用

該領域暴露出與同類型代碼視圖計數器的計用途:

我可以將字段添加到視圖,但一旦我添加它,它只是顯示爲「破碎/失蹤」

這三個文件都位於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 { 
+0

查看https://drupal.org/node/856186 – 2013-09-16 04:52:37

回答

2

我這通過在我的.info文件中定義視圖文件來工作。

files[] = funwithviews.views.inc 
files[] = funwithviews_handler_field_fwv_counter.inc 

hook_views_handlers()不再處於Views中。

0

它的工作,但如果你在hook_handlers把die('something');它不是called.this一個取巧的辦法,而不是一個標準方式。

/** 
* 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', 
    ), 
    ), 
); 
} 

也許是因爲你的模塊名稱(以視圖結尾),drupal鉤子解析器沒有正確檢測到它。 我確實有這個問題(我的模塊名稱以視圖my_module結束)。

0

文件[] = funwithviews.views.inc
文件[] = funwithviews_handler_field_fwv_counter.inc

第一行是沒有必要的。只有第二。在Drupal 7中,您可能只包含.info文件中的文件。
文件funwithviews.views.inc將通過hook_views_api在你.module文件自動包含。