You are here

function better_jump_menu_plugin_style_better_jump_menu::render_grouping_sets in Better Jump Menu 7

@inheritdoc

Overrides views_plugin_style::render_grouping_sets

File

views/better_jump_menu_plugin_style_better_jump_menu.inc, line 118
Contains the list style plugin.

Class

better_jump_menu_plugin_style_better_jump_menu
Style plugin to render each item in a select box.

Code

function render_grouping_sets($sets, $level = 0) {
  $output = array();
  foreach ($sets as $set) {
    $row = reset($set['rows']);

    // Render as a grouping set.
    if (is_array($row) && isset($row['group'])) {
      $output .= theme(views_theme_functions('views_view_grouping', $this->view, $this->display), array(
        'view' => $this->view,
        'grouping' => $this->options['grouping'][$level],
        'grouping_level' => $level,
        'rows' => $set['rows'],
        'title' => $set['group'],
      ));
    }
    else {
      if ($this
        ->uses_row_plugin()) {
        foreach ($set['rows'] as $index => $row) {
          $this->view->row_index = $index;
          $depths[$index] = (int) strip_tags(decode_entities($this
            ->get_field($this->view->row_index, $this->options['depth'])));
        }
        $min_depth = (int) min($depths);
        foreach ($set['rows'] as $index => $row) {
          $this->view->row_index = $index;

          // Get the depth.
          $depth = (int) $depths[$index] + 1 - $min_depth;

          // Get the path.
          $path = trim(strip_tags(decode_entities($this
            ->get_field($this->view->row_index, $this->options['path']))));

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

          // Use drupal_parse_url() to preserve query and fragment in case the user
          // wants to do fun tricks.
          $url_options = drupal_parse_url($path);
          $set['rows'][$index] = array(
            '#href' => url($url_options['path'], $url_options),
            '#title' => trim(strip_tags(decode_entities($this->row_plugin
              ->render($row)))),
            '#original_link' => array(
              'depth' => $depth,
            ),
            '#below' => array(),
          );
        }
      }
      $options = array();
      $settings = array(
        'hide' => $this->options['hide'],
        'button' => $this->options['text'],
        'title' => $this->options['label'],
        'choose' => $this->options['choose'],
        'inline' => $this->options['inline'],
        'indent' => $this->options['indent'],
        'type' => 'view',
        'view' => $this->view,
      );
      _better_jump_menu_convert_to_options_array($set['rows'], $options, $settings);
      $output[] = drupal_get_form('better_jump_menu', $options, $settings);
    }
  }
  unset($this->view->row_index);
  return $output;
}