You are here

function file_entity_file_formatter_info in File Entity (fieldable files) 7

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

Implements hook_file_formatter_info().

File

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

Code

function file_entity_file_formatter_info() {
  $formatters = array();

  // Allow file field formatters to be reused for displaying the file entity's
  // file pseudo-field.
  if (module_exists('file')) {
    foreach (field_info_formatter_types() as $field_formatter_type => $field_formatter_info) {
      if (in_array('file', $field_formatter_info['field types'])) {
        $formatters['file_field_' . $field_formatter_type] = array(
          'label' => $field_formatter_info['label'],
          'view callback' => 'file_entity_file_formatter_file_field_view',
        );
        if (isset($field_formatter_info['settings'])) {
          $formatters['file_field_' . $field_formatter_type] += array(
            'default settings' => $field_formatter_info['settings'],
            'settings callback' => 'file_entity_file_formatter_file_field_settings',
          );
        }
      }
    }
  }

  // Add a simple file formatter for displaying an image in a chosen style.
  if (module_exists('image')) {
    $formatters['file_image'] = array(
      'label' => t('Image'),
      'default settings' => array(
        'image_style' => '',
      ),
      'view callback' => 'file_entity_file_formatter_file_image_view',
      'settings callback' => 'file_entity_file_formatter_file_image_settings',
    );
  }
  return $formatters;
}