2

I need to join a custom table custom_table on a View my_view.

I have a module created called join_table

The nid is the referential id (the nid is what ties the two table to the view).

Then, I need to take the info the column price in custom_table and be able to display using my Views template.

I'm completely lost.

1
5

Example:

/**
 * Implements hook_views_api()
 * @file modulename.module
 */
function modulename_views_api() {
  return array('api' => 2);
}

/**
 * Implements hook_views_data()
 * @file modulename.views.inc
 */
function modulename_views_data() {
  $data['custom_table']['table']['join']['node'] = array(
    'left_field' => 'nid',
    'field' => 'nid',
  );

  $data['custom_table']['price'] = array(
    'title'  => 'Title',
    'help'   => 'Help',
    'group'  => t('Node'),
    'field'  => array('handler' => 'views_handler_field'),
    'sort'   => array('handler' => 'views_handler_sort'),
    'filter' => array('handler' => 'views_handler_filter_string'),
  );

  return $data;
}

Read more info in oficial manual Describing tables to Views

4
  • Here's my issue with this: Where's the indication that this code needs to be placed in a .inc file? Where's the indication on how this code needs to be called through a module. These tutorials in Drupal are half-assed and not helpful at all. They cause me more consternation than anything else. That is why I am asking here, and I don't feel a "RTFM" type of response is at all appropriate.
    – kylex
    Oct 6 '11 at 2:30
  • 2
    Try treehouseagency.com/blog/neil-hastings/2010/01/19/…, that's a tutorial for a basic implementation of hook_views_data(), where you need to place it and so on.
    – Berdir
    Oct 6 '11 at 2:49
  • 3
    ok, i added example
    – xandeadx
    Oct 6 '11 at 5:42
  • @xandeadx: awesome!
    – kylex
    Oct 6 '11 at 17:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.