You are here

function quicktabs_style_plugin::render in Quick Tabs 6.3

Same name and namespace in other branches
  1. 6.2 includes/quicktabs_style_plugin.inc \quicktabs_style_plugin::render()
  2. 7.3 includes/quicktabs_style_plugin.inc \quicktabs_style_plugin::render()

File

includes/quicktabs_style_plugin.inc, line 69
Add Quicktabs style plugins to Views.

Class

quicktabs_style_plugin
Style plugin to display Quicktabs.

Code

function render() {
  if (empty($this->row_plugin)) {
    vpr('views_plugin_style_default: Missing row plugin');
    return;
  }
  $view = $this->view;
  $machine_name = 'view__' . $view->name . '__' . $view->current_display;

  // Group the rows according to the grouping field, if specified.
  $sets = $this
    ->render_grouping($this->view->result, $this->options['grouping']);
  $tabs = array();
  foreach ($sets as $title => $records) {
    if ($this
      ->uses_row_plugin()) {
      $rows = array();
      foreach ($records as $row_index => $row) {
        $this->view->row_index = $row_index;
        $rows[] = $this->row_plugin
          ->render($row);
      }
    }
    else {
      $rows = $records;
    }

    // If grouped, we'll be using the group title for each tab.
    if ($this->options['grouping']) {

      // Remove labels from titles.
      $grouping_field = $this->options['grouping'];
      if ($this->view->field[$grouping_field]->options['label']) {
        $title = str_replace($this->view->field[$grouping_field]->options['label'] . ': ', '', $title);
      }
      $tabs[] = array(
        'title' => $title,
        'content' => $rows,
      );
    }
    else {
      foreach ($rows as $index => $row) {
        $title = $this
          ->get_field($index, $this->options['tab_title_field']);
        $tabs[] = array(
          'title' => $title,
          'content' => $row,
        );
      }
    }
  }
  $output = theme('quicktabs_views_render', $view, $tabs, $machine_name);

  // If doing a live preview, add the JavaScript directly to the output.
  if (isset($view->live_preview) && $view->live_preview) {
    $js = drupal_add_js();
    $qtsettings = array();
    foreach ($js['setting'] as $settings) {
      if (isset($settings['quicktabs']['qt_' . $machine_name])) {
        $qtsettings = $settings['quicktabs']['qt_' . $machine_name];
        break;
      }
    }
    $output .= "<script type=\"text/javascript\">\n";
    $output .= "Drupal.settings.quicktabs = Drupal.settings.quicktabs || {};\n";
    $output .= "jQuery.extend(Drupal.settings.quicktabs, " . drupal_to_js(array(
      'qt_' . $machine_name => $qtsettings,
    )) . ");\n";
    $output .= "</script>\n";
  }
  unset($view->row_index);
  return $output;
}