Index: vimeo_link_formatter.module =================================================================== --- vimeo_link_formatter.module (revision 20) +++ vimeo_link_formatter.module (working copy) @@ -18,12 +18,12 @@ 'settings' => vimeo_link_formatter_default_settings_player(), ); - // @todo Implement the rest of this. - // $formatters['vimeo_link_formatter_thumbnail'] = array( - // 'label' => t('Vimeo Thumbnail'), - // 'description' => t('Displays the thumbnail of Vimeo video, if the URL is for a Vimeo.com video page.'), - // 'field types' => array('link_field'), - // ); + $formatters['vimeo_link_formatter_thumbnail'] = array( + 'label' => t('Vimeo Thumbnail'), + 'description' => t('Displays the thumbnail of Vimeo video, if the URL is for a Vimeo.com video page.'), + 'field types' => array('link_field'), + 'settings' => vimeo_link_formatter_default_settings_thumbnail(), + ); return $formatters; } @@ -35,6 +35,7 @@ module_load_include('admin.inc', 'vimeo_link_formatter'); // Call the function which handles this formatter. $function = __FUNCTION__ . '_' . $instance['display'][$view_mode]['type']; + return call_user_func($function, $field, $instance, $view_mode); } @@ -54,6 +55,7 @@ function vimeo_link_formatter_field_formatter_view(&$entity_type, &$entity, &$field, &$instance, &$langcode, &$items, &$display) { // Call the function which handles this formatter. $function = __FUNCTION__ . '_' . $display['type']; + return call_user_func($function, $entity_type, $entity, $field, $instance, $langcode, $items, $display); } @@ -137,3 +139,54 @@ ); return $defaults; } + +/** + * Vimeo.com's default thumb settings. + * + * @see vimeo_link_formatter_field_formatter_settings_form_vimeo_link_formatter_thumbnail() + * + * @return Array + * Default values keyed by the setting name. + */ +function vimeo_link_formatter_default_settings_thumbnail() { + $defaults = array( + // Cast values to the type that Form API forms return them as. + 'thumb_size' => (String) 'medium', + ); + return $defaults; +} + +/** + * Implementation of vimeo_link_formatter_field_formatter_view_FORMATTER(); + * + * @return Vimeo remote image html + */ +function vimeo_link_formatter_field_formatter_view_vimeo_link_formatter_thumbnail($entity_type, $entity, $field, $instance, $langcode, $items, $display) { + + $ret = array(); + + foreach ($items as $delta => $item) { + // Extract the ID from the URL. + preg_match('@http://(www\.)?vimeo\.com/([0-9]+)@', $item['url'], $matches); + + $url = array(); + + if ($id = $matches[2]) { + $hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$id.php")); + + $thumb_size = $display['settings']['thumb_size'] ? $display['settings']['thumb_size'] : 'medium'; + + $thumb_url = $hash[0]['thumbnail_'.$thumb_size]; + + $img = theme('image', array('path' => $thumb_url, 'alt' => $hash[0]['title'])); + + $ret[] = array('#markup' => $img); + } + else { + // The link is not a valid Vimeo.com link. + // @todo Handle this better, perhaps with node-form validation or more + // formatter settings? + } + } + return $ret; +} \ No newline at end of file Index: vimeo_link_formatter.admin.inc =================================================================== --- vimeo_link_formatter.admin.inc (revision 20) +++ vimeo_link_formatter.admin.inc (working copy) @@ -186,3 +186,44 @@ return $form; } + +/** + * Implementation of hook_field_formatter_settings_summary_FORMATTER(). + * + * @return String + * Translated text string summarizing the formatter settings. + */ +function vimeo_link_formatter_field_formatter_settings_summary_vimeo_link_formatter_thumbnail($field, $instance, $view_mode) { + $display = $instance['display'][$view_mode]; + $settings = $display['settings']; + $summary = t('Use Vimeo video thumb of size "@thumb_size"', array( + '@thumb_size' => $settings['thumb_size'], + )); // we use t() for translation and placeholders to guard against attacks + return $summary; +} + +/** + * Implementation of hook_field_formatter_settings_form_FORMATTER(). + */ +function vimeo_link_formatter_field_formatter_settings_form_vimeo_link_formatter_thumbnail($field, $instance, $view_mode, $form, &$form_state) { + //This gets the view_mode where our settings are stored + $display = $instance['display'][$view_mode]; + //This gets the actual settings + $settings = $display['settings']; + //Initialize the element variable + $element = array(); + //Add your select box + $element['thumb_size'] = array( + '#type' => 'select', // Use a select box widget + '#title' => t('Thumbnail Size'), // Widget label + '#description' => t('Select what size of Vimeo thumbnail'), // Helper text + '#default_value' => $settings['thumb_size'], // Get the value if it's already been set + '#options' => array( + 'small' => 'Small', + 'medium' => 'Medium', + 'large' => 'Large', + ), + ); + + return $element; +} \ No newline at end of file