You are here

function mediafront_views_query_alter in MediaFront 7

Same name and namespace in other branches
  1. 6.2 mediafront.module \mediafront_views_query_alter()
  2. 6 mediafront.module \mediafront_views_query_alter()

Implements hook_views_query_alter().

File

./mediafront.module, line 565

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_add_css('.media-nid-hidden { display:none; }', array(
        'type' => 'inline',
      ));

      // 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($view->base_field, array_keys($query->fields))) {
      $query
        ->add_field($query->base_table, $view->base_field);
    }
  }
}