Thursday, February 10, 2011

Create views for the custom table

1. Create an custom module "customviews"

2. Paste the below code

Here debug_user is the table name

debug_id,uid,uname are the field names present in that table

change this code according to your convenient


<?php

function customviews_views_api() {
return array(
'api' => 2,
'path' => drupal_get_path('module', 'customviews') . '/modules',
);
}

function customviews_views_data() {
$data['debug_user']['table']['group'] = t('Custom View');

$data['debug_user']['table']['base'] = array(
'field' => 'debug_id',
'title' => t('Custom table'),
'help' => t('Stores information about custom table.'),
'weight' => 10,
);

// Following are the fields of the table 'custom_views'
// Field:custom_id
$data['debug_user']['debug_id'] = array(
'title' => t('ID'),
'help' => t('ID of the custom table.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);

$data['debug_user']['uid'] = array(
'title' => t('UID'),
'help' => t('UID of the custom table.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);


// Field:custom_title
$data['debug_user']['uname'] = array(
'title' => t('Name'),
'help' => t('Name of the field.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);

return $data;
}

?>

No comments:

Post a Comment