views_handler_field_file_filemime.inc

Definition of views_handler_field_file_filemime.

File

modules/system/views_handler_field_file_filemime.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Definition of views_handler_field_file_filemime.
  5. */
  6. /**
  7. * Field handler to add rendering MIME type images as an option on the filemime field.
  8. *
  9. * @ingroup views_field_handlers
  10. */
  11. class views_handler_field_file_filemime extends views_handler_field_file {
  12. function option_definition() {
  13. $options = parent::option_definition();
  14. $options['filemime_image'] = array('default' => FALSE, 'bool' => TRUE);
  15. return $options;
  16. }
  17. function options_form(&$form, &$form_state) {
  18. $form['filemime_image'] = array(
  19. '#title' => t('Display an icon representing the file type, instead of the MIME text (such as "image/jpeg")'),
  20. '#type' => 'checkbox',
  21. '#default_value' => !empty($this->options['filemime_image']),
  22. );
  23. parent::options_form($form, $form_state);
  24. }
  25. function render($values) {
  26. $data = $values->{$this->field_alias};
  27. if (!empty($this->options['filemime_image']) && $data !== NULL && $data !== '') {
  28. $fake_file = (object) array('filemime' => $data);
  29. $data = theme('file_icon', array('file' => $fake_file));
  30. }
  31. return $this->render_link($data, $values);
  32. }
  33. }