私はモジュールに取り組んでおり、いくつかのフィールドをビューに公開し、いくつかのカスタムフィルターを提供したいと考えています。しかし、致命的なエラーを発生させずにビュークラスを拡張することはできません。私のコードは次のようになります。 views_handler_fieldを拡張しようとするまで、すべてうまくいきます。
<?php
// $Id$
/**
* @files
* Provide functionality for views.
*/
/**
* Get some data and set some handlers.
*/
function custom_views_data() {
$data = array();
$data['custom']['table']['group'] = t('custom');
$data['custom']['table']['join'] = array(
'node' => array(
'left_field' => 'nid',
'field' => 'nid',
),
);
// Has form
$data['custom']['is_checked'] = array(
'title' => t('Has contest form'),
'help' => t('Filter based on presence of a contest form. Nodes with contest forms will equal 1.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => FALSE,
),
'filter' => array(
'handler' => 'views_handler_filter_string',
)
);
return $data;
}
// If you remove everything below here, things work as expected
/**
*
* Define custom handlers.
*/
function custom_views_handlers() {
return array(
'info' => array(
'path' => drupal_get_path('module', 'custom')
),
'handlers' => array(
'custom_handler_is_checked_field' => array(
'parent' => 'views_handler_field'
)
)
);
}
/**
* This class fails with Fatal error: Class 'views_handler_field' not found
*
*/
class custom_handler_is_checked_field extends views_handler_field {}
あなたのクラスコードはあなたのフックと同じファイル、別名.moduleまたは.views.incファイルにありますか? views_handler_fieldは別のファイルにあり、必要な場合にのみ読み込まれるため、これは機能しません。
「パス」で定義したフォルダ内で、クラスと同じ名前で末尾が「.inc」の別のファイルに移動する必要があります。 (あなたの場合、あなたのモジュールディレクトリ、多くのファイルを持つ大きなモジュールの場合、それらをviewsディレクトリに置くことをお勧めします)
次に、必要に応じて、ビューに自動的にクラスが含まれますincludeing views_handler_fieldを含むファイル(フックで親関係を定義したため)。