You are here

function views_accordion_style_plugin::render in Views Accordion 6

Same name and namespace in other branches
  1. 7 views_accordion_style_plugin.inc \views_accordion_style_plugin::render()

Render the display in this style.

File

./views_accordion_style_plugin.inc, line 136
Provide an accordion style plugin for Views. This file is autoloaded by views.

Class

views_accordion_style_plugin
Implementation of views_plugin_style().

Code

function render() {
  $output = parent::render();

  // dpm($this->display->handler->get_option('fields')); // for dev-troubleshooting
  // Preparing the js variables and adding the js to our display
  // we do it here so we dont have it run once every group
  drupal_add_js(drupal_get_path('module', 'views_accordion') . '/views-accordion.js');
  $view_settings['keeponeopen'] = $this->options['keep-one-open'];
  $view_settings['startopen'] = $this->options['start-open'];
  $view_settings['rowstartopen'] = $this->options['row-start-open'];
  $view_settings['speed'] = check_plain($this->options['speed']) * 1000;
  $view_settings['disablecloseothers'] = $this->options['disable-close-others'];
  $view_settings['grouping'] = $this->options['grouping'] ? 1 : 0;
  $view_settings['togglelinks'] = $this->options['toggle-links'];

  // Dont auto-cycle if only one item.
  $view_settings['autocycle'] = count($this->view->result) > 1 ? $this->options['auto-cycle'] : 0;
  $view_settings['autocyclespeed'] = check_plain($this->options['auto-cycle-speed']) * 1000;
  $view_settings['display'] = 'views-accordion-' . $this->view->name . '-' . $this->view->current_display;
  $view_settings['usegroupheader'] = $view_settings['grouping'] ? $this->options['use-grouping-header'] : 0;
  $view_settings['enableheaderlinks'] = $this->options['header-is-link'] ? 1 : 0;
  $view_id = 'views-accordion-' . $this->view->name . '-' . $this->view->current_display;
  if ($view_settings['usegroupheader'] == 1) {
    $view_settings['header'] = 'h3.' . $view_id;
  }

  // Used to get the first field to be used as the accordion header
  if ($view_settings['usegroupheader'] == 0) {
    $i = 0;
    foreach ($this->view->field as $id => $value) {
      if ($i == 0 && $value->options['exclude'] == 0) {
        $view_settings['header'] = 'views-field-' . str_replace('_', '-', $id);
        $i++;
      }
    }
  }
  drupal_add_js(array(
    'views_accordion' => array(
      $view_id => $view_settings,
    ),
  ), 'setting');
  return $output;
}