I have a table that’s been created by a module. I need to include some of its fields into an existing view.
I tried using the table wizard module, but all it does is create a separate view for that table. I’d like to be able to choose fields from that table to be added into an existing view as additional fields, or through relationships or something like that. Is there a workaround to do what I’m trying to do?
Ah. Views. Took me a while as well. This answer is for Drupal 6 and in the abstract shows how to define fields as well as using a relationship to allow the fields to link to the node table.
Inside modulename.module, you want a function that goes:
Then you want to make a file called modulename.views.inc and define a function like this:
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; }