home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (filefield_meta_handler_field_samplerate.inc)

This example Drupal source code file (filefield_meta_handler_field_samplerate.inc) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

array, check_plain, default, form, form_state, function, options, output, php, raw, return, value, values, weight

The filefield_meta_handler_field_samplerate.inc Drupal example source code

<?php
// $Id: filefield_meta_handler_field_samplerate.inc,v 1.1 2010/04/24 06:28:03 quicksketch Exp $

/**
 * @file
 * A special handler that properly formats bit rate fields as kHz.
 */

/**
 * Render a field as a readable value in hours, minutes, and seconds.
 *
 * @ingroup views_field_handlers
 */
class filefield_meta_handler_field_samplerate extends views_handler_field_numeric {
  function option_definition() {
    $options = parent::option_definition();

    $options['format'] = array('default' => 'default', 'translatable' => TRUE);

    // Remove the separator options since we don't need them.
    unset($options['separator']);

    return $options;
  }

  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);

    // Remove the separator options since we don't need them.
    unset($form['separator']);

    $form['prefix']['#weight'] = 10;
    $form['suffix']['#weight'] = 10;
    $form['format'] = array(
      '#type' => 'select',
      '#title' => t('Format'),
      '#default_value' => $this->options['format'],
      '#options' => array(
        'default' => t('Default (kHz)'),
        'raw' => t('Raw numberic value'),
      ),
    );
  }

  function render($values) {
    $value = $values->{$this->field_alias};

    // Check to see if hiding should happen before adding prefix and suffix.
    if ($this->options['hide_empty'] && empty($value) && ($value !== 0 || $this->options['empty_zero'])) {
      return '';
    }

    switch ($this->options['format']) {
      case 'raw':
        $output = $value;
        break;
      default:
        $output = theme('filefield_meta_samplerate', $value);
    }

    return check_plain($this->options['prefix']) . $output . check_plain($this->options['suffix']);
  }
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal filefield_meta_handler_field_samplerate.inc source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.