You are here

function pdfpreview_field_formatter_view in PDFPreview 7

Same name and namespace in other branches
  1. 7.2 pdfpreview.module \pdfpreview_field_formatter_view()

Implements hook_field_formatter_view()

See also

_pdfpreview_create_preview()

File

./pdfpreview.module, line 45
This file contains hooks for the pdfpreview module

Code

function pdfpreview_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  foreach ($items as $delta => $item) {
    $file = file_load($item['fid']);
    $element[$delta]['#file'] = $file;
    if ($item['filemime'] == 'application/pdf') {
      $item['preview'] = _pdfpreview_create_preview($file);
      $element[$delta] = array(
        '#preview' => $item['preview'],
        '#markup' => theme($display['type'], array(
          'item' => $item,
          'field' => $instance,
        )),
      );
    }
    else {
      module_load_include('inc', 'file', 'file.field');
      $display['type'] = 'file_default';
      $tmp = file_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, array(
        $item,
      ), $display);
      $element[$delta] = $tmp[0];
    }
  }
  return $element;
}