Custom Drupal Modules and Views

| | Comments (0) | TrackBacks (1)

I'm working with a client on a Drupal site where another programmer has implemented several custom content types via a module, not CCK. I'm researching how to integrate this with the Views module, and found this useful information so far.

The hook of note seems to be hook_views_tables to get the view editing interface to know about the columns in our custom table.

Here is the start of a function to return the information to the Views module. In this example we use product_id as the primary key of our table, which is the same as the node's nid. This only exposes the name of the product to the view, but more columns and tables will be added later.

// hook to tell views about our tables
function mymodule_views_tables() {
 $tables['mymodule_product'] = array(
   'name' => 'mymodule_product',
   'join' => array(
     'left' => array(
       'table' => 'node',
       'field' => 'nid'
       ),
      'right' => array(
        'field' => 'product_id'
       )
     ),
     'fields' => array(
       'name' => array('name' => t('Product: Name'),  
                       'sortable' => TRUE),
     ),
   );

 return $tables;
}

1 TrackBacks

Listed below are links to blogs that reference this entry: Custom Drupal Modules and Views.

TrackBack URL for this entry: http://bloggy.com/cgi-bin/mt4/mt-tb.cgi/3756

Continuing my exploration of custom modules and views, here is my code for allowing view builders to filter entries based on a status field, say "special offers" that is represented in our module's database table by an integer with 1... Read More

Leave a comment

About

A blog by Barry Hoggard, owner of Tristan Media LLC.

About this Entry

This page contains a single entry by published on June 26, 2008 12:53 PM.

Be careful when buying a domain on Dotster is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.