您已经接近了,但请检查一下:Views 在模块代码中提供了有关如何执行此操作的文档。查看views/docs/views.api.php 并阅读!
http://drupalcontrib.org/api/drupal/contributions%21views%21views.api.php/7是那里的源代码,充满了有用的评论(在底部查看源代码)。
基本上你需要实现 hook_views_data_alter 来告诉 Views 你的表。这将允许您加入。要显示连接字段,您需要在传递给 hook_views_data_alter 的数组中设置正确的处理程序。查看views.api.php中的第343行
<?php
// This table references the {node} table. The declaration below creates an
// 'implicit' relationship to the node table, so that when 'node' is the base
// table, the fields are automatically available.
$data['example_table']['table']['join'] = array(
// Index this array by the table name to which this table refers.
// 'left_field' is the primary key in the referenced table.
// 'field' is the foreign key in this table.
'node' => array(
'left_field' => 'nid',
'field' => 'nid',
),
);
// Next, describe each of the individual fields in this table to Views. This
// is done by describing $data['example_table']['FIELD_NAME']. This part of
// the array may then have further entries:
// - title: The label for the table field, as presented in Views.
// - help: The description text for the table field.
// - relation: A description of any relation handler for the table field.
// - field: A description of any field handler for the table field.
// - sort: A description of any sort handler for the table field.
// - filter: A description of any filter handler for the table field.
// - argument: A description of any argument handler for the table field.
// - area: A description of any handler for adding content to header,
// footer or as no result behaviour.
//
// The handler descriptions are described with examples below.
// Node ID table field.
$data['example_table']['nid'] = array(
'title' => t('Example content'),
'help' => t('Some example content that references a node.'),
// The nid is a foreign key to the {node} table. This allows us to (easily)
// add a relationship handler for this table field, making all the table
// fields for the related node available.
'relationship' => array(
'base' => 'node', // The name of the table to join with
'field' => 'nid', // The name of the field to join with
'handler' => 'views_handler_relationship',
'label' => t('Example node'),
),
);