You are here

function views_plugin_style_jump_menu::render in Views (for Drupal 7) 6.3

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

Render the display in this style.

This is overridden so that we can render our grouping specially.

Overrides views_plugin_style::render

File

plugins/views_plugin_style_jump_menu.inc, line 90
Contains the table style plugin.

Class

views_plugin_style_jump_menu
Style plugin to render each item as a row in a table.

Code

function render() {
  $sets = $this
    ->render_grouping($this->view->result, $this->options['grouping']);

  // Turn this all into an $options array for the jump menu.
  $this->view->row_index = 0;
  $options = array();
  $paths = array();
  foreach ($sets as $title => $records) {
    foreach ($records as $row_index => $row) {
      $this->view->row_index = $row_index;
      $path = html_entity_decode(strip_tags($this
        ->get_field($this->view->row_index, $this->options['path'])), ENT_QUOTES);

      // Putting a '/' in front messes up url() so let's take that out
      // so users don't shoot themselves in the foot.
      if (strpos($path, '/') === 0) {
        $path = substr($path, 1);
      }

      // use parse_url() to preserve query and fragment in case the user
      // wants to do fun tricks.
      $url = parse_url($path);
      $url_options = array();
      if (isset($url['query'])) {
        $path = strtr($path, array(
          '?' . $url['query'] => '',
        ));
        $url_options['query'] = $url['query'];
      }
      if (isset($url['fragment'])) {
        $path = strtr($path, array(
          '#' . $url['fragment'] => '',
        ));
        $url_options['fragment'] = $url['fragment'];
      }
      $path = url($path, $url_options);
      $field = html_entity_decode(strip_tags($this->row_plugin
        ->render($row)), ENT_QUOTES);
      $key = md5($path . $field) . "::" . $path;
      if ($title) {
        $options[$title][$key] = $field;
      }
      else {
        $options[$key] = $field;
      }
      $paths[$path] = $key;
      $this->view->row_index++;
    }
  }
  unset($this->view->row_index);
  $default_value = '';
  if ($this->options['default_value']) {
    $lookup_options = array();

    // We need to check if the path is absolute
    // or else language is not taken in account.
    if ($this->view->display[$this->view->current_display]->display_options['fields'][$this->options['path']]['absolute']) {
      $lookup_options['absolute'] = TRUE;
    }
    $lookup_url = url($_GET['q'], $lookup_options);
    if (!empty($paths[$lookup_url])) {
      $default_value = $paths[$lookup_url];
    }
  }
  ctools_include('jump-menu');
  $settings = array(
    'hide' => $this->options['hide'],
    'button' => $this->options['text'],
    'choose' => $this->options['choose'],
    'default_value' => $default_value,
  );
  return drupal_get_form('ctools_jump_menu', $options, $settings);
}