function video_embed_field_field_formatter_view in Video Embed Field 7.2
Same name and namespace in other branches
- 7 video_embed_field.module \video_embed_field_field_formatter_view()
Implements hook_field_formatter_view().
File
- ./
video_embed_field.field.inc, line 444 - Implement a video field.
Code
function video_embed_field_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
$settings = $display['settings'];
if ($display['type'] == 'video_embed_field_thumbnail' && $display['settings']['image_link'] == 'content') {
$path = entity_uri($entity_type, $entity);
}
foreach ($items as $delta => $item) {
// Create the render array for the description.
if (isset($item['description']) && $item['description'] && $settings['description'] && $instance['settings']['description_field']) {
$description = array(
'#prefix' => '<div class="video-embed-description">',
'#markup' => check_plain($item['description']),
'#suffix' => '</div>',
);
$alt = $item['description'];
}
else {
$description = array();
$alt = '';
}
// Render the field.
if ($display['type'] == 'video_embed_field') {
$element[$delta] = array(
array(
'#theme' => 'video_embed_field_embed_code',
'#url' => $item['video_url'],
'#style' => $settings['video_style'],
'#video_data' => !empty($item['video_data']) ? unserialize($item['video_data']) : array(),
),
);
}
elseif ($display['type'] == 'video_embed_field_url') {
$element[$delta] = array(
array(
'#markup' => url($item['video_url']),
),
);
}
elseif ($display['type'] == 'video_embed_field_thumbnail') {
if (isset($item['thumbnail_path'])) {
if ($display['settings']['image_link'] == 'source') {
if ($ret = parse_url($item['video_url'])) {
if (!isset($ret["scheme"])) {
$item['video_url'] = "http://{$item['video_url']}";
}
}
$path = array(
'path' => $item['video_url'],
'options' => array(),
);
}
$element[$delta] = array(
'#theme' => 'image_formatter',
'#item' => array(
'uri' => $item['thumbnail_path'],
'alt' => $alt,
),
'#image_style' => $display['settings']['image_style'],
'#path' => isset($path) ? $path : '',
);
}
else {
$element[$delta] = array();
}
}
elseif ($display['type'] == 'video_embed_field_thumbnail_colorbox') {
if (isset($item['thumbnail_path'])) {
if ($ret = parse_url($item['video_url'])) {
if (!isset($ret["scheme"])) {
$item['video_url'] = "http://{$item['video_url']}";
}
}
$element[$delta] = array(
array(
'#theme' => 'video_embed_field_colorbox_code',
'#image_url' => $item['thumbnail_path'],
'#image_style' => $display['settings']['image_style'],
'#image_alt' => $alt,
'#video_url' => $item['video_url'],
'#video_style' => $display['settings']['video_style'],
'#video_data' => unserialize($item['video_data']),
),
);
}
else {
$element[$delta] = array();
}
}
elseif ($display['type'] == 'video_embed_field_url_colorbox') {
$path = video_embed_field_get_ajax_url($item['video_url'], $display['settings']['video_style']);
$element[$delta] = array(
array(
'#markup' => url($path['path'], $path['options']),
),
);
}
// Get the HTML instead of the array, because we append it to the suffix.
// This way, the thumbnail link doesn't make the description a link as well.
$description_html = drupal_render($description);
$pos = isset($settings['description_position']) ? $settings['description_position'] : 'bottom';
if ($pos == 'top') {
$element[$delta]['#prefix'] = isset($element[$delta]['#prefix']) ? $element[$delta]['#prefix'] : '';
$element[$delta]['#prefix'] = $description_html . $element[$delta]['#prefix'];
}
else {
$element[$delta]['#suffix'] = isset($element[$delta]['#suffix']) ? $element[$delta]['#suffix'] : '';
$element[$delta]['#suffix'] .= $description_html;
}
}
return $element;
}