You are here

function quicktabs_style_plugin::render in Quick Tabs 7.3

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

Render the display in this style.

Overrides views_plugin_style::render

File

includes/quicktabs_style_plugin.inc, line 82
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;
  $qt_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.
      foreach (element_children($this->options['grouping']) as $key => $value) {
        if (!empty($this->view->field[$this->options['grouping'][$key]['field']]->options['label'])) {
          $title = str_replace($this->view->field[$this->options['grouping'][$key]['field']]->options['label'] . ': ', '', $title);
        }
      }
      $contents = '';
      foreach ($rows as $row) {
        $contents .= '<div class="quicktabs-views-group">' . $row . '</div>';
      }
      $tabs[] = array(
        'title' => $title,
        'contents' => array(
          '#markup' => $contents,
        ),
      );
    }
    else {
      foreach ($rows as $index => $row) {
        $title = $this
          ->get_field($index, $this->options['tab_title_field']);
        $tabs[] = array(
          'title' => $title,
          'contents' => array(
            '#markup' => $row,
          ),
        );
      }
    }
  }
  $overrides = array(
    'style' => $this->options['tab_style'],
    'sorted' => TRUE,
  );
  $quicktabs = quicktabs_build_quicktabs($qt_name, $overrides, $tabs);
  $output = drupal_render($quicktabs);

  // 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['settings']['data'] as $settings) {
      if (isset($settings['quicktabs']['qt_' . $qt_name])) {
        $qtsettings = $settings['quicktabs']['qt_' . $qt_name];
        break;
      }
    }
    $output .= "<script type=\"text/javascript\">\n";
    $output .= "Drupal.settings.quicktabs = Drupal.settings.quicktabs || {};\n";
    $output .= "jQuery.extend(Drupal.settings.quicktabs, " . json_encode(array(
      'qt_' . $qt_name => $qtsettings,
    )) . ");\n";
    $output .= "</script>\n";
  }
  unset($view->row_index);
  return $output;
}