1

我正在尝试创建自己的自定义格式输出视图。我在这段代码中取得了部分成功:

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 目录中,要么放在我模块自己的插件目录中。我也无法在网上找到任何好的示例,也没有得到任何有用的错误消息来帮助我调试。

是否有关于如何创建自定义视图处理程序的适当文档?或者你能提供一个可行的例子吗?

非常感谢!

4

1 回答 1

1

这里有一个教程:http ://groups.drupal.org/node/10129 。向下滚动到“Writing Views 2 style and row plugins”。在教程示例中,他们创建了样式和行插件。

作为替代方案,我尝试只创建一个样式插件,与您的类似,只是我将“使用行插件”设置为 false。然后我可以从我的views-view-myplugin.tpl.php 模板中访问原始行数据。

于 2011-07-01T23:05:19.073 回答