array( 'containers' => array( 'default' => array( 'label' => t('Default Filefield Styles'), 'weight' => 10, 'preview theme' => 'filefield_styles_preview_default', 'data' => array(), 'filter callback' => 'filefield_styles_styles_formatter_filter_default', 'themes' => array( 'field_formatter_styles' => 'filefield_styles_field_formatter_styles_default', 'styles' => 'filefield_styles_styles_default', 'preview' => 'filefield_styles_preview_default', ), ), ), ), ); if (module_exists('imagecache')) { $containers['filefield']['containers']['image'] = array( 'label' => t('Image Styles'), 'weight' => 0, 'preview theme' => 'image_style_preview', 'data' => array( 'streams' => array( 'public', 'private', ), 'mimetypes' => array( 'image/png', 'image/gif', 'image/jpeg', ), ), 'filter callback' => 'filefield_styles_styles_formatter_filter', 'themes' => array( 'field_formatter_styles' => 'filefield_styles_field_formatter_styles', 'styles' => 'filefield_styles_styles', 'preview' => 'image_style_preview', ), 'help' => t('Imagecache will transform images to your choosing, such as by scaling and cropping. You can !manage.', array('!manage' => l(t('manage your imagecache styles here'), 'admin/build/imagecache'))), ); } return $containers; } function theme_filefield_styles_styles_default($file_type, $style_name, $object, $variables = array()) { $path = drupal_get_path('module', 'filefield_styles'); $alt = $title = t('Thumbnail for !filename.', array('!filename' => $object->filename)); $thumbnail = theme('image', $path . '/images/file-unknown.png', $alt, $title, array('class' => 'file-unknown')); return $thumbnail; } function theme_filefield_styles_preview_default($variables) { return 'default: theme_filefield_styles_preview_default'; } function theme_filefield_styles_field_formatter_styles_default($variables) { $file = $variables['object']; $file_url = file_create_url($file->filepath); return l($file->filename, $file_url); } /** * The 'Default' file style is a fallback when nothing else resolves. */ function filefield_styles_styles_formatter_filter_default() { // This is a fallback to handle all generic files. return TRUE; } function filefield_styles_styles_formatter_filter($variables) { if (isset($variables['object'])) { $object = $variables['object']; $container = $variables['container']; return in_array($object->filemime, $container['data']['mimetypes']); } } function theme_filefield_styles_styles($file_type, $style_name, $object, $variables = array()) { $alt = $title = $object->description; return theme('imagecache', $style_name, $object->filepath, $alt, $title); } /** * Implements hook_styles_presets(). */ function filefield_styles_styles_presets() { $presets = array(); foreach (imagecache_presets() as $style) { $presets['filefield'][$style['presetname']]['image'] = array($style['presetname']); $presets['filefield'][$style['presetname']]['default'] = array($style['presetname']); } return $presets; } /** * Implements hook_styles_styles(). */ function filefield_styles_styles_styles() { $styles = array(); foreach (imagecache_presets() as $style) { // Save the module & storage for the Image module namespace. $style['image_module'] = $style['module']; $style['image_storage'] = $style['storage']; $styles[$style['presetname']] = $style; } $default_styles = $styles; return array( 'filefield' => array( 'containers' => array( 'image' => array('styles' => $styles), 'default' => array('styles' => $default_styles), ), ), ); } function theme_filefield_styles_image_style_preview($field_type, $container_name, $style_name) { $styles = image_styles(); if (isset($styles[$style_name])) { module_load_include('inc', 'image', 'image.admin'); drupal_add_css(drupal_get_path('module', 'image') . '/image.admin.css'); // Ensure we revert the module & storage namespace for the Image module. $styles[$style_name]['module'] = $styles[$style_name]['image_module']; $styles[$style_name]['storage'] = $styles[$style_name]['image_storage']; return theme('image_style_preview', array('style' => $styles[$style_name])); } } /** * Implement hook_theme(). */ function filefield_styles_theme() { return array( // Theme functions in filefield_styles.module. 'filefield_style' => array( 'variables' => array( 'style_name' => NULL, 'path' => NULL, 'alt' => '', 'title' => '', 'attributes' => array(), 'getsize' => TRUE, ), ), // Theme functions in filefield_styles.admin.inc. 'filefield_style_list' => array( 'variables' => array('styles' => NULL), ), // Display a image style preset. 'filefield_styles_image_style_preview' => array( 'variables' => array('field_type' => NULL, 'container_name' => NULL, 'style_name' => NULL), ), // 'filefield_styles_field_formatter_styles' => array( // 'variables' => array('element' => NULL, 'style' => NULL), // ), 'filefield_styles_styles' => array( 'variables' => array('field_type' => NULL, 'style_name' => NULL, 'object' => NULL, 'variables' => array()), ), // 'filefield_styles_field_formatter_styles_default' => array( // 'variables' => array('element' => NULL, 'style' => NULL), // ), 'filefield_styles_styles_default' => array( 'variables' => array('field_type' => NULL, 'style_name' => NULL, 'object' => NULL, 'variables' => array()), ), 'filefield_styles_preview_default' => array( 'variables' => array('field_type' => NULL, 'container_name' => NULL, 'style_name' => NULL), ), ); }