You are here

class views_handler_field_taxonomy_image in Taxonomy Image 6

Field handler to provide an embedded image.

Hierarchy

Expanded class hierarchy of views_handler_field_taxonomy_image

1 string reference to 'views_handler_field_taxonomy_image'
taxonomy_image_views_data in ./taxonomy_image.views.inc
Implementation of hook_views_data().

File

./views_handler_field_taxonomy_image.inc, line 13
Views integration for Taxonomy Image module.

View source
class views_handler_field_taxonomy_image extends views_handler_field {

  /**
   * Define options available for this field.
   */
  function option_definition() {
    $options = parent::option_definition();
    $options['imagecache_preset'] = array(
      'default' => '',
    );
    $options['link_to_taxonomy'] = array(
      'default' => FALSE,
    );
    return $options;
  }

  /**
   * Build option configuration form.
   */
  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);
    $form['link_to_taxonomy'] = array(
      '#title' => t('Link this image to its term page'),
      '#type' => 'checkbox',
      '#default_value' => !empty($this->options['link_to_taxonomy']),
    );

    // If ImageCache module is found, add its presets as available options
    // for how to display the image.
    if (module_exists('imagecache')) {
      $raw_presets = imagecache_presets();
      $presets[''] = t('Default');
      foreach ($raw_presets as $preset_id => $preset_info) {
        $preset = $preset_info['presetname'];
        $presets[$preset] = $preset;
      }
      $form['imagecache_preset'] = array(
        '#type' => 'select',
        '#title' => t('ImageCache preset'),
        '#options' => $presets,
        '#default_value' => $this->options['imagecache_preset'],
      );
    }
  }

  /**
   * Render field output to the browser.
   */
  function render($values) {
    $image = '';
    $tid = $values->{$this->field_alias};
    if (!$tid) {
      return;
    }

    // Render image. If ImageCache preset is specified, use it.
    if ($this->options['imagecache_preset']) {
      $image = taxonomy_image_display($tid, NULL, $this->options['imagecache_preset']);
    }
    else {
      $image = taxonomy_image_display($tid);
    }

    // Output image as a link, if option is set.
    if ($this->options['link_to_taxonomy']) {
      $image = l($image, drupal_get_path_alias(taxonomy_term_path(taxonomy_get_term($tid))), array(
        'html' => TRUE,
      ));
    }
    return $image;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
views_handler_field_taxonomy_image::options_form function Build option configuration form.
views_handler_field_taxonomy_image::option_definition function Define options available for this field.
views_handler_field_taxonomy_image::render function Render field output to the browser.