You are here

function file_entity_link_file_view in File Entity Link 7

Implements hook_file_view Enter description here ...

Parameters

unknown_type $file:

unknown_type $view_mode:

unknown_type $langcode:

File

./file_entity_link.module, line 35

Code

function file_entity_link_file_view($file, $view_mode, $langcode) {
  $settings = variable_get(FILE_ENTITY_LINK_SETTINGS_VAR, array());
  if (isset($settings[$file->type][$view_mode]) && $settings[$file->type][$view_mode] && !empty($file->referencing_entity)) {
    $entity_type = '';
    $referencing_entity = $file->referencing_entity;

    // If we are on a Field Collection Item
    if ($referencing_entity instanceof FieldCollectionItemEntity) {
      $entity_type = $referencing_entity
        ->hostEntityType();
      $referencing_entity = $referencing_entity
        ->hostEntity();
    }
    else {
      if (isset($referencing_entity->nid)) {
        $entity_type = 'node';
      }
      elseif (isset($referencing_entity->tid)) {
        $entity_type = 'taxonomy_term';
      }
    }
    if (!empty($entity_type)) {
      switch ($entity_type) {
        default:
          $uri = entity_uri('node', $referencing_entity);
      }
    }
    if (!empty($uri)) {
      $file->content['file'] = array(
        '#contents' => $file->content['file'],
        '#uri' => $uri,
        '#theme' => 'file_entity_link_add_link',
      );
    }
  }
}