diff --git a/file_entity.file_api.inc b/file_entity.file_api.inc index 339d91f..88f2771 100644 --- a/file_entity.file_api.inc +++ b/file_entity.file_api.inc @@ -308,16 +308,22 @@ function file_view_file($file, $displays = 'full', $langcode = NULL) { } } - // If a render element was returned by a formatter or the file type's default - // view callback, add some defaults to it and return it. - if (isset($element)) { - $element += array( + // As a last resort, fall back to showing a link to the file. + if (! isset($element)) { + $element = array( + '#theme' => 'file_link', '#file' => $file, - '#view_mode' => $view_mode, - '#language' => $langcode, ); - return $element; } + + // Add defaults and return the element. + $element += array( + '#file' => $file, + '#view_mode' => $view_mode, + '#language' => $langcode, + ); + + return $element; } /** diff --git a/file_entity.module b/file_entity.module index 8930149..d404aba 100644 --- a/file_entity.module +++ b/file_entity.module @@ -77,6 +77,10 @@ function file_entity_help($path, $arg) { case 'admin/structure/file-types': $output = '

' . t('When a file is uploaded to this website, it is assigned one of the following types, based on what kind of file it is.') . '

'; return $output; + case 'admin/structure/file-types/manage/%/display/preview': + case 'admin/structure/file-types/manage/%/file-display/preview': + drupal_set_message(t('Some modules rely on the Preview view mode to function correctly. Changing these settings may break parts of your site.'), 'warning'); + break; } } @@ -351,10 +355,21 @@ function file_entity_entity_info_alter(&$entity_info) { $entity_info['file']['entity keys']['bundle'] = 'type'; $entity_info['file']['bundles'] = array(); $entity_info['file']['uri callback'] = 'file_entity_uri'; - $entity_info['file']['view modes']['full'] = array( - 'label' => t('Full'), - 'custom settings' => FALSE, + $entity_info['file']['view modes'] += array( + 'teaser' => array( + 'label' => t('Teaser'), + 'custom settings' => TRUE, + ), + 'full' => array( + 'label' => t('Full content'), + 'custom settings' => FALSE, + ), + 'preview' => array( + 'label' => t('Preview'), + 'custom settings' => TRUE, + ), ); + foreach (file_info_file_types() as $type => $info) { $info += array( // Provide a default administration path for Field UI, but not if 'admin' diff --git a/file_entity.pages.inc b/file_entity.pages.inc index ee58c90..8f7055e 100644 --- a/file_entity.pages.inc +++ b/file_entity.pages.inc @@ -230,11 +230,7 @@ function file_entity_edit($form, &$form_state, $file) { ); } - $form['preview'] = array( - '#theme' => 'file_link', - '#file' => $file, - '#weight' => -5, - ); + $form['preview'] = file_view_file($file, 'preview'); // Add the buttons. $form['actions'] = array('#type' => 'actions');