我有一个由模块创建的表.我需要将其中的一些字段包含在现有视图中.
我尝试使用the table wizard module,但它只是为该表创建一个单独的视图.我希望能够从该表中选择要添加到现有视图中的字段作为附加字段,或通过关系或类似的东西.是否有解决方法来做我想做的事情?
解决方法:
啊.视图.我也花了一段时间.这个答案适用于Drupal 6,并在摘要中展示了如何定义字段以及使用关系来允许字段链接到节点表.
function modulename_views_api() {
return array(
'api' => 2,
);
}
然后你想创建一个名为modulename.views.inc的文件并定义一个这样的函数:
function modulename_views_data() { $data['modulename_table'] = array( 'table' => array( 'group' => 'ModuleName', 'title' => 'Module name title', ), 'join' => array( // to join to node, we'll use a field in modulename_table called 'nid' 'node' => array( 'left_field' => 'nid', 'field' => 'nid', ), ), ); // Now we define the fields in the table like this // check out modules/views/handlers to see more specific handlers $data['modulename_table']['fieldname'] = array( 'title' => 'fieldname', 'help' => 'fieldname description', 'field' => array( 'handler' => 'views_handler_field', ), ); $data['modulename_table']['nid'] = array( 'title' => 'related node', 'help' => 'the field that relates back to {node}', // here we implement a relationship to nid 'relationship' => array( 'base' => 'node', 'field' => 'nid', 'handler' => 'views_handler_relationship', 'label' => 'modulename row node', ), // this relationship can be turned on in views ); return $data; }