function views_json_views_pre_render in Views Datasource 7
Implements hook_views_pre_render().
File
- ./
views_json.module, line 15
Code
function views_json_views_pre_render(&$view) {
if (isset($view->plugin_name) && $view->plugin_name == 'views_json') {
// Support for Video field.
if (!empty($view->result)) {
// Process each View result.
foreach ($view->result as $row => $result) {
// Only process the entity fields defined by the View.
foreach ($view->field as $field_name => $field) {
if ($field instanceof views_handler_field_field) {
if ($field->field_info['type'] == 'video') {
$options = $field->options;
$video = $field
->get_value($view->result[$row]);
if (empty($video)) {
continue;
}
switch ($options['type']) {
case 'video_formatter_thumbnail':
$settings = $options['settings'];
$thumbnail = $video[0]['thumbnailfile'];
if (!empty($settings['image_style'])) {
$url = image_style_url($settings['image_style'], $thumbnail->uri);
}
else {
$url = file_create_url($thumbnail->uri);
}
break;
default:
$url = file_create_url($video[0]['uri']);
break;
}
$render_array = array(
'#type' => 'markup',
'#markup' => filter_xss($url),
);
// Substitute embed code with URL. @todo Add support for escaped embed codes.
$view->result[$row]->{'field_' . $field_name}[0]['rendered'] = $render_array;
}
}
}
}
}
}
}