Custom Views Handler Drupal 7 Template

module.info

; Views includes
files[] = includes/views/module.views.inc
 
; Views handlers
files[] = includes/views/handlers/module_handler1.inc

——-

module.module

/**
 * Implements hook_views_api().
 */
function module_views_api() {
  return array(
    'api' => 3,
    'path' => drupal_get_path('module', 'module') . '/includes/views',
  );
}

——————

module.views.inc

<?php

/**
 * File description
 */

/**
 * Implements hook_views_data()
 */
function module_views_data() {
  $data = array();

  $data['AN_EXISTED_TABLE']['handler1'] = array(
    'title' => t('Handler 1'),
    'help' => t('Displays handler 1.'),
    'area' => array(
      'handler' => 'module_handler1',
    ),
  );

  return $data;
}

——————

module_handler1.inc

<?php
 
/**
 * File description
 */
class module_handler1 extends views_handler_area {
 
  function option_definition() {
    $options = parent::option_definition();
    return $options;
  }
 
  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);
 
    unset($form['empty']);
  }
 
  function render($empty = FALSE) {
    if (!$empty) {      
      foreach ($this->view->argument as $name => $argument) {        
          // If it is single value...
          if (count($argument->value) == 1) {            
            // RENDER CONTENT
            return  $argument->value; // FUNCTION RENDER THIS VALUE
          }        
      }
    }
 
    return '';
  }
}
Technorati Tags: ,,
Advertisements

2 responses to “Custom Views Handler Drupal 7 Template

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: