Active
Project:
Media: Vimeo
Version:
7.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
5 Feb 2013 at 18:00 UTC
Updated:
3 Apr 2016 at 21:01 UTC
Jump to comment: Most recent
Hi,
I modify the media_vimeo.formatters.inc to add a "Show as URL" checkbox to the Vimeo Preview Image formatter in order to get the image url in my views. Here's what I did:
$formatters['media_vimeo_image'] = array(
'label' => t('Vimeo Preview Image'),
'file types' => array('video'),
'default settings' => array(
'image_style' => '',
'show_as_url' => '',
),
'view callback' => 'media_vimeo_file_formatter_image_view',
'settings callback' => 'media_vimeo_file_formatter_image_settings',
); /**
* Implements hook_file_formatter_FORMATTER_view().
*/
function media_vimeo_file_formatter_image_view($file, $display, $langcode) {
$scheme = file_uri_scheme($file->uri);
if ($scheme == 'vimeo') {
$wrapper = file_stream_wrapper_get_instance_by_uri($file->uri);
$image_style = $display['settings']['image_style'];
$valid_image_styles = image_style_options(FALSE);
$show_as_url = $display['settings']['show_as_url'];
if ($show_as_url) {
if (empty($image_style) || !isset($valid_image_styles[$image_style])) {
$ouput = $wrapper->getOriginalThumbnailPath();
} else {
$output = image_style_url($image_style,$wrapper->getLocalThumbnailPath());
}
$element = array(
'#type' => 'markup',
'#markup' => $output,
);
} else {
if (empty($image_style) || !isset($valid_image_styles[$image_style])) {
$element = array(
'#theme' => 'image',
'#path' => $wrapper->getOriginalThumbnailPath(),
'#alt' => $file->filename,
);
}
else {
$element = array(
'#theme' => 'image_style',
'#style_name' => $image_style,
'#path' => $wrapper->getLocalThumbnailPath(),
'#alt' => $file->filename,
);
}
}
return $element;
}
}
/**
* Implements hook_file_formatter_FORMATTER_settings().
*/
function media_vimeo_file_formatter_image_settings($form, &$form_state, $settings) {
$element = array();
$element['image_style'] = array(
'#title' => t('Image style'),
'#type' => 'select',
'#options' => image_style_options(FALSE),
'#default_value' => $settings['image_style'],
'#empty_option' => t('None (original image)'),
);
$element['show_as_url'] = array(
'#title' => t('Show as URL'),
'#type' => 'checkbox',
'#default_value' => false
);
return $element;
}
2 problems:
The "Show as URL" option isn't saved.
The url I get is something like "http://styles/img_pano_80_80/http/b.vimeocdn.com/ts/187/551/187551494_64..." and not an external url
Anyone can help me solving this?
Comments
Comment #1
RumpledElf commentedI've hit this too and am surprised it isn't already an option. Will make a module that adds this view mode and link it back here.
Comment #2
leksat commentedTemporary solution: https://drupal.org/sandbox/Leksat/2057775
Comment #3
rob c commentedEuuh folks, what about this?
http://drupal.org/project/file_entity_link
Comment #4
devin carlson commentedYou can accomplish this by rendering the video using the "URL to file" formatter provided by the core File module.
Comment #6
brightboldUnless I'm fundamentally misunderstanding something here, the "URL to file" formatter is not helpful, because it provides a URL to the video itself, and what we're looking for is a URL to the video preview image. I can select either "URL to file" as the formatter or "Rendered file" as the formatter with "Preview" as the view mode, but I don't see any way (other than the sandbox modules posted above) to get the URL to the preview image.