Skip to content

Instantly share code, notes, and snippets.

@blainelang
Created August 25, 2013 00:09
Show Gist options
  • Save blainelang/6331110 to your computer and use it in GitHub Desktop.
Save blainelang/6331110 to your computer and use it in GitHub Desktop.
Example HOOK_views_data for 2 "related" custom tables and includes a relationship back to the users table. http://internetdevels.com/blog/describe-custom-table-for-views
/* Define Views interface for custom data tables */
function as_dashboard_views_data() {
$data = array();
$data['communication_builder_contact_list'] = array(
'table' => array(
'group' => t('AdvisorStream'),
'title' => t('contact list'),
'help' => t('Broker Contact List Names'),
'base' => array(
'field' => 'id',
'title' => t('contact list'),
'help' => t('Broker Contact List Names'),
),
),
'id' => array(
'title' => t('List ID'),
'help' => t('Internal ID for the list'),
'field' => array(
'handler' => 'views_handler_field',
),
),
'title' => array(
'title' => t('List Name'),
'help' => t('Name of the contact list'),
'field' => array(
'handler' => 'views_handler_field',
),
),
'uid' => array(
'title' => t('User ID'),
'help' => t('Links to user entity'),
'field' => array(
'handler' => 'views_handler_field_user',
),
'filter' => array(
'handler' => 'views_handler_filter_user_current',
),
'relationship' => array(
'base' => 'users',
'field' => 'uid',
'handler' => 'views_handler_relationship',
'label' => t('User')
),
),
);
$data['communication_builder_contact_list_member']= array(
'table' => array(
'group' => t('AdvisorStream'),
'join' => array(
'communication_builder_contact_list' => array(
'left_field' => 'id',
'field' => 'list_id',
),
),
),
'email_address' => array(
'title' => t('Email Address'),
'help' => t('Email address for contact'),
'field' => array(
'handler' => 'views_handler_field',
),
),
);
return $data;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment