function template_preprocess_media_browser_plus_views_view_media_browser in Media Browser Plus 7.3
Display the view as a media browser.
See also
template_preprocess_media_views_view_media_browser()
File
- views/
media_browser_plus.views.inc, line 139 - Provide Views data and handlers for media.module.
Code
function template_preprocess_media_browser_plus_views_view_media_browser(&$vars) {
module_load_include('inc', 'media', 'includes/media.browser');
$view = $vars['view'];
$display_handler = $vars['view']->display_handler;
// If this is a media browser display add some more JS.
// Re-uses vast parts of template_preprocess_media_views_view_media_browser().
if ($display_handler instanceof media_views_plugin_display_media_browser) {
$fids = array();
foreach ($view->result as $index => $result) {
$fids[$index] = $result->fid;
}
$files = file_load_multiple($fids);
foreach ($files as $file) {
// Add url/preview to the file object.
media_browser_build_media_item($file);
}
// Add the files to JS so that they are accessible inside the browser.
drupal_add_js(array(
'media' => array(
'files' => array_values($files),
),
), 'setting');
// Add the browser parameters to the settings and that this display exists.
drupal_add_js(array(
'media' => array(
'browser' => array(
'params' => media_get_browser_params(),
'views' => array(
$vars['view']->name => array(
$vars['view']->current_display,
),
),
),
),
), 'setting');
// Add media browser javascript and CSS.
drupal_add_js(drupal_get_path('module', 'media') . '/js/plugins/media.views.js');
}
// Add classes and wrappers from the style plugin.
$handler = $vars['view']->style_plugin;
$class = explode(' ', $handler->options['class']);
$class = array_map('drupal_clean_css_identifier', $class);
$wrapper_class = explode(' ', $handler->options['wrapper_class']);
$wrapper_class = array_map('drupal_clean_css_identifier', $wrapper_class);
$vars['class'] = implode(' ', $class);
$vars['wrapper_class'] = implode(' ', $wrapper_class);
$vars['wrapper_prefix'] = '<div class="' . implode(' ', $wrapper_class) . '">';
$vars['wrapper_suffix'] = '</div>';
$vars['list_type_prefix'] = '<' . $handler->options['type'] . ' id="media-browser-library-list" class="' . implode(' ', $class) . '">';
$vars['list_type_suffix'] = '</' . $handler->options['type'] . '>';
// Run theming variables through a standard Views preprocess function.
template_preprocess_views_view_unformatted($vars);
// Now add our own stuff - based on the set options.
// Add the js / css library.
drupal_add_library('media_browser_plus', 'media_browser_plus');
// Add more information for the JS integration.
$vars['options']['view_id'] = $view->name;
$vars['options']['view_display_id'] = $view->current_display;
// Add settings for the js library.
drupal_add_js(array(
'mbp' => array(
'views' => array(
$view->name . ':' . $view->current_display => $vars['options'],
),
),
), 'setting');
// Special handling of the navigation. We abuse a area handler to add and
// configure the navigation - that way it's very flexible.
// Check if a navigation handler is configured.
$vars['folders'] = NULL;
foreach (array(
'header',
'footer',
) as $area) {
foreach ($display_handler->handlers[$area] as $handler) {
if ($handler instanceof media_browser_plus_views_handler_area_navigation) {
$vars['folders'] = $handler
->render_custom();
break 2;
}
}
}
}