Hello there,
I've been trying to add my custom modules table as a base table in views. This is how I've tried to implement it:
/mymodule.module
/**
* Implements hook_views_api().
*/
function mymodule_views_api() {
return array(
'api' => 3,
'path' => drupal_get_path('module', 'mymodule') . '/includes/views',
);
}
/mymodule.install
/**
* Implements hook_schema().
*/
function mymodule_schema() {
$schema = array();
$schema['mymodule_domains'] = array(
'description' => 'Storage for the domains retrieved',
'fields' => array(
'id' => array(
'description' => 'Primary key of the record.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'domain' => array(
'description' => 'Domain name.',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
),
'type' => array(
'description' => 'Domain type.',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
),
'status' => array(
'description' => 'Domain status',
'type' => 'int',
'length' => 1,
'not null' => FALSE,
),
),
'primary key' => array('id'),
);
return $schema;
}
/includes/views/domains.view.inc
/**
* Implements hook_views_data().
*/
function mymodule_views_data() {
$data = array();
// Putting the table into its own groups so that we can recognize in the UI
// where it comes from
$data['mymodule_domains']['table']['group'] = t('MyModule');
// Making the 'mymodule_domains' table a base table so a View can created based on it
$data['mymodule_domains']['table']['base'] = array(
'field' => 'id',
'title' => t('MyModule Domains'),
'help' => t('Contains domains exposed to Views.'),
'weight' => -10,
);
// The ID field
$data['mymodule_domains']['id'] = array(
'title' => t('ID'),
'help' => t('The domain ID.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
);
// The Domain field
$data['mymodule_domains']['domain'] = array(
'title' => t('Domain Name'),
'help' => t('The domain name.'),
'field' => array(
'handler' => 'views_handler_field',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
// The Type field
$data['mymodule_domains']['type'] = array(
'title' => t('Type'),
'help' => t('The domain type.'),
'field' => array(
'handler' => 'views_handler_field',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
// The Status field
$data['mymodule_domains']['status'] = array(
'title' => t('Status'),
'help' => t('The domain status.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
);
return $data;
}
I have disabled, uninstalled, re-enabled the module then cleared all caches including the views cache, however the table still does not show up as a base table when creating a new view. What am I doing wrong?
Cheers
Dan Doyle
Comments
Comment #1
mustanggb commentedClosing this as outdated to tidy up a bit around here. If you're still having problems with the latest release please create a new issue.