blainelang of Nextide
1/20/2014 - 6:41 PM

Example HOOK_views_data for 2 "related" custom tables and includes a relationship back to the users table. http://internetdevels.com/blog/d

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;

};