You are here

function file_entity_file_formatter_file_image_view in File Entity (fieldable files) 7

Same name and namespace in other branches
  1. 7.3 file_entity.module \file_entity_file_formatter_file_image_view()
  2. 7.2 file_entity.module \file_entity_file_formatter_file_image_view()

Implements hook_file_formatter_FORMATTER_view().

Returns a drupal_render() array to display an image of the chosen style.

This formatter is only capable of displaying local images. If the passed in file is either not local or not an image, nothing is returned, so that file_view_file() can try another formatter.

1 string reference to 'file_entity_file_formatter_file_image_view'
file_entity_file_formatter_info in ./file_entity.module
Implements hook_file_formatter_info().

File

./file_entity.module, line 423
Extends Drupal file entities to be fieldable and viewable.

Code

function file_entity_file_formatter_file_image_view($file, $display, $langcode) {
  $scheme = file_uri_scheme($file->uri);
  $local_wrappers = file_get_stream_wrappers(STREAM_WRAPPERS_LOCAL);
  if (isset($local_wrappers[$scheme]) && strpos($file->filemime, 'image/') === 0) {
    if (!empty($display['settings']['image_style'])) {
      $element = array(
        '#theme' => 'image_style',
        '#style_name' => $display['settings']['image_style'],
        '#path' => $file->uri,
      );
    }
    else {
      $element = array(
        '#theme' => 'image',
        '#path' => $file->uri,
      );
    }
    return $element;
  }
}