You are here

function node_gallery_api_file_view in Node Gallery 7

Implements hook_file_view().

Parameters

object $file: file object

string $view_mode: current view mode

string $langcode: language code

File

./node_gallery_api.module, line 404
Node Gallery module.

Code

function node_gallery_api_file_view($file, $view_mode, $langcode) {
  $settings = variable_get('node_gallery_api_file_link_settings', array());
  if (!empty($settings[$file->type][$view_mode]) && $settings[$file->type][$view_mode] != 'none' && !empty($file->referencing_entity)) {
    if ($settings[$file->type][$view_mode] == 'gallery_item') {
      $uri = entity_uri('node', $file->referencing_entity);
    }
    elseif ($settings[$file->type][$view_mode] == 'gallery') {
      $relationships = node_gallery_api_get_relationships(NULL, $file->referencing_entity->nid);
      if (!empty($relationships)) {
        $r = reset($relationships);
        $gallery = node_load($r->ngid);
        $uri = entity_uri('node', $gallery);
      }
    }
  }
  if (!empty($uri)) {
    $file->content['file'] = array(
      '#contents' => !empty($file->content['file']) ? $file->content['file'] : '',
      '#uri' => $uri,
      '#theme' => 'node_gallery_api_file_display_link',
    );
  }
}