View on external tables in Views with custom module

Categories

Component ID

1996980

Component name

View on external tables in Views with custom module

Component type

module

Maintenance status

Development status

Component security advisory coverage

not-covered

Component created

Component changed

Component body

Step 1) Create module info file " custom_views_table.info ".

name = custom_views_table
description = Create external table view.
package = Custom Drupal 7 Development
core = 7.x

Step 2) Create module file " custom_views_table.module ".

    function custom_views_table_views_api(){ // Register view API information
        $view = array();
        $view = array('api'=>3,
        'path'=>drupa_get_path('module','custom_views_table')                
        );
        return $view;
    }


    function custom_views_table_views_data(){ //Describes data tables
        $table = array();
        
        $table['custom table']['table']['group'] => t('custom table');
        $table['custom table']['table']['base'] =>array(
                'title'=>t('Courses'), //Courses is Custom external table
                'field'=>'id',
                'help'=>t('Contains courses, departments, and descriptions')); 
                
                
        $table['custom table']['title']=>array(
                'title'=>t('Course name'), //Custom external table field
                'help'=>t('Course name'),
                'field'=> array(
                    'handler'=> 'views_handler_field',
                    'click sortable'=> TRUE,),
                'sort'=>array(handler=>'views_handler_sort',),
                'filter'=>array(handler=>'views_handler_filter_string',),
                'argument'=>array(handler=>'views_handler_argument_string',),  
        );
    
        $table['custom table']['Department']=>array(
                'title'=>t('Department'), //Custom external table field
                'help'=>t('Department name'),
                'field'=>array(
                    'handler'=>'views_handler_field',
                    'click sortable'=>TRUE,),
                'sort'=>array('handler'=>'views_handler_sort',),
                'filter'=>array('handler'=>'views_handler_filter_string',),
                'argument'=>array('handler'=>'views_handler_argument_string'),      
        
        );
        
        
        $table['custom table']['Description']=>array(
                'title'=>t('description'), //Custom external table field
                'help'=>t('description name'),
                'field'=>array('handler'=>'views_handler_field',
                'click  sortable'=>TRUE,),
                'sort'=>array('handler'=>'views_handler_field'),
                'filter'=>array('handler'=>'views_handler_filter_string',),
                'argument'=>array('handler'=>'views_handler_argument_string',),
         
        );
        
        
        $table['custom table']['id'] = array(
                'title' => t('Unique identifier'), //Custom external table field
                'help' => t('Primary key for table'),
                'field' => array('handler' => 'views_handler_field'),
                'argument' => array('handler' => 'views_handler_argument_numeric'),
                'filter' => array('handler' => 'views_handler_filter_numeric'),
                'sort' => array('handler' => 'views_handler_sort_numeric'));
                
    return $table;
    
    }

Thanks:
Gajendra Kumar Sharma