我正在尝试创建自己的自定义格式输出视图。我在这段代码中取得了部分成功:
my_module.module:
<?php
function my_module_views_api() { // your module name into hook_views_api
return array(
'api' => 2,
// might not need the line below, but in any case, the last arg is the name of your module
'path' => drupal_get_path('module', 'my_module'),
);
}
?>
my_module.views.inc:
<?php
/**
* Implementation of hook_views_plugins().
*/
function my_module_views_plugins() {
$path = drupal_get_path('module', 'my_module');
return array(
'style' => array(
'my_module' => array(
'title' => t('my_module'),
'handler' => 'views_plugin_style_default',
'theme' => 'my_module',
'theme path' => $path . '/theme',
'theme file' => 'my-module.tpl.php',
'uses row plugin' => TRUE,
'uses row class' => TRUE,
'uses grouping' => TRUE,
'uses options' => TRUE,
'type' => 'normal',
)
),
);
}
?>
主题/我的模块.tpl.php:
<?php
/**
* @file views-view-unformatted.tpl.php
* Default simple view template to display a list of rows.
*
* @ingroup views_templates
*/
if (!empty($title)):
print $title;
endif;
foreach ($rows as $id => $row):
?>
ROW:
<?php
print_r($row);
endforeach;
?>
以上是成功的,因为它将使用我的自定义 my-module.tpl.php 来输出行。但是,这些行是预先格式化的,可以由 views_plugin_style_default 处理程序推测。我花了几个小时尝试创建自己的此类处理程序,但没有成功,要么将其直接放在 views/plugins 目录中,要么放在我模块自己的插件目录中。我也无法在网上找到任何好的示例,也没有得到任何有用的错误消息来帮助我调试。
是否有关于如何创建自定义视图处理程序的适当文档?或者你能提供一个可行的例子吗?
非常感谢!