function template_preprocess_lightgallery_view in Lightgallery 7
Display a view as a Lightgallery style.
File
- ./
lightgallery.module, line 97
Code
function template_preprocess_lightgallery_view(&$vars) {
$view = $vars['view'];
$result = $vars['rows'];
$vars['rows'] = array();
// Get values from options form.
$options = $view->style_plugin->options['lightgallery'];
// Get fields.
$fields =& $view->field;
// Render fields with view style plugin.
$handler = $view->style_plugin;
$rendered_rows = $handler
->render_fields($result);
$thumb_field = $options['thumb_field'];
$image_field = $options['image_field'];
$title_field = $options['title'];
// Overwrite $vars['rows'] with rendered fields and thumbnails.
foreach ($rendered_rows as $num => $row) {
$rendered_slide = FALSE;
$rendered_thumb = FALSE;
$rendered_title = FALSE;
foreach ($row as $field_name => $field) {
// Check if field is thumb field.
if ($field_name == $thumb_field) {
$rendered_thumb = $field;
}
// Check if field is image field.
if ($field_name == $image_field) {
$rendered_slide = $field;
}
// Check if field is title field.
if ($field_name == $title_field) {
$rendered_title = $field;
}
// Store field labels.
$vars['field_labels'][$num] = $fields[$field_name]
->label();
}
$vars['rows'][$num]['slide'] = $rendered_slide;
$vars['rows'][$num]['thumb'] = $rendered_thumb;
$vars['rows'][$num]['title'] = $rendered_title;
// Set row style to display: hidden or block.
$vars['row_styles'][$num] = 'display: block;';
}
// Set unique id, so that multiple instances on one page can be created.
$unique_id = uniqid();
$vars['id'] = $unique_id;
// Add libraries and settings.
$option_set = _lightgallery_build_option_set($options);
lightgallery_add($unique_id, $option_set);
}