Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagephp
linenumberstrue
/**
 * Implements hook_views_api
 */
function example_views_api() {
  return array(
    'api' => 3,
    'path' => drupal_get_path('module', 'example'),
  );
}

example.views.inc

Code Block
languagephp
titleexample.views.inc
linenumberstrue
/**
 * @file
 * Views definitions for 'example'
 */
/**
 * Implements hook_views_data().
 */
function example_views_data() {
  $data = array();
  // Add Example group
  $data['example']['table']['group'] = t('Example');
  $data['example']['table']['join'] = array(
    // #global is a special flag which let's a table appear all the time.
    '#global' => array(),
  );
  // Add custom field
  $data['example']['custom_field'] = array(
    'title' => t('Custom Field'),
    'help' => t('Provides a custom field.'),
    'field' => array(
      'handler' => 'example_handler_custom_field',
    ),
  );
  return $data;
}

example.info

Code Block
languagephptitleexample.info
linenumberstrue
name = Example Module
description = This module provides the skeleton for a custom Views field handler
core = 7.x
version = 7.x-1.0
dependencies[] = views
files[] = views/example_handler_custom_field.inc

views/example_handler_custom_field.inc

Code Block
languagephptitleviews/example_handler_custom_field.inc
linenumberstrue
/**
 * @file
 * Definition of example_handler_custom_field
 */
 
/**
 * Provides a custom views field. 
 */
class example_handler_custom_field extends views_handler_field {
  function option_definition() {
    $options = parent::option_definition();
    return $options;
  }
 
  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);
  }
 
  function query() {
    // do nothing -- to override the parent query.
  }
 
  function render($data) {
    // If the devel module is enabled, you may view all of the
    // data provided by fields previously added in your view.
    // dpm($data);
    // Insert PHP code here, or display greeting.
    $output = t("Hello World!");
    return $output;  
  }
}

...