array( 'label' => t('File icon'), 'field types' => array('file'), ), ); } /** * Implements file_field_formatter_info(). * * Adding new file format markup */ function file_icon_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { $element = array(); switch ($display['type']) { case 'file_icon_only': foreach ($items as $delta => $item) { $element[$delta] = array( '#markup' => file_icon_link(array('file' => (object) $item)), ); } } return $element; } /** * The markup for the new format */ function file_icon_link($variables) { $file = $variables['file']; $url = file_create_url($file->uri); $icon = theme('file_icon', array('file' => $file)); // Set options as per anchor format described at // http://microformats.org/wiki/file-format-examples $options = array( 'attributes' => array( 'type' => $file->filemime . '; length=' . $file->filesize, 'target' => '_blank', ), ); // to use l() to show image $options['html'] = TRUE; return '' . l($icon, $url, $options) . ''; }