function mediafront_views_query_alter in MediaFront 6
Same name and namespace in other branches
- 6.2 mediafront.module \mediafront_views_query_alter()
- 7 mediafront.module \mediafront_views_query_alter()
Implements hook_views_query_alter().
File
- ./
mediafront.module, line 620
Code
function mediafront_views_query_alter(&$view, &$query) {
// Check to make sure this is the block playlist.
if (mediafront_block_show($view)) {
// We need to add the nid to the view if it does not exist...
if (!isset($view->field['mediafront_nid'])) {
// Add an inline style to hide the hidden media nids.
drupal_set_html_head('<style type="text/css">.media-nid-hidden { display:none; }</style>');
// Add a nid to the view.
$handler = views_get_handler('node', 'nid', 'field');
$handler
->set_default_options();
$handler->field_alias = 'mediafront_nid';
$handler->table = 'node';
$handler->field = 'nid';
$handler->real_field = 'nid';
$handler->options['label'] = '';
$handler->options['alter']['alter_text'] = 1;
$handler->options['alter']['text'] = '<div class="media-nid-hidden">[mediafront_nid]</div>';
$handler->options['id'] = 'mediafront_nid';
$handler
->init($view, $handler->options);
$query
->add_field('node', 'nid', 'mediafront_nid');
$view->field['mediafront_nid'] = $handler;
$view->display_handler->handlers['field']['mediafront_nid'] = $handler;
}
}
/**
* This is a HACK until I can convince the views maintainers to take my patch found at
* http://drupal.org/node/857946
*/
if ($view->style_plugin->definition['handler'] == 'mediafront_plugin_style_player') {
if (!isset($query->fields) || !in_array('nid', array_keys($query->fields))) {
$query
->add_field($query->base_table, 'nid');
}
}
}