filefield_meta_handler_field_tags.inc 1.19 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
<?php

/**
 * @file
 * A special handler that renders ID3 tags attached to a file.
 */

/**
 * Render a field as a readable value in hours, minutes, and seconds.
 *
 * @ingroup views_field_handlers
 */
class filefield_meta_handler_field_tags extends views_handler_field {
  function option_definition() {
    $options = parent::option_definition();
    $default = reset(array_keys(filefield_meta_tags()));
    $options['tag'] = array('tag' => $default, 'required' => TRUE, 'translatable' => TRUE);
    return $options;
  }

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

    $form['relationship']['#weight'] = -2;
    $form['tag'] = array(
      '#type' => 'select',
      '#title' => t('ID3 tag'),
      '#required' => TRUE,
      '#default_value' => $this->options['tag'],
      '#options' => filefield_meta_tags(),
      '#description' => t('Select the tag to be rendered. If needing multiple tags, add another ID3 tags field.'),
      '#weight' => -1,
    );
  }

  function render($values) {
    $value = unserialize($values->{$this->field_alias});
    $tag = $this->options['tag'];
    if (isset($value[$tag])) {
      return check_plain($value[$tag]);
    }
  }
}