• Main Page
  • Related Pages
  • Modules
  • Classes
  • Files
  • File List
  • File Members

plugins/views_plugin_style_jump_menu.inc

Go to the documentation of this file.
00001 <?php
00012 class views_plugin_style_jump_menu extends views_plugin_style {
00013   function option_definition() {
00014     $options = parent::option_definition();
00015 
00016     $options['hide'] = array('default' => FALSE);
00017     $options['path'] = array('default' => '');
00018     $options['text'] = array('default' => 'Go', 'translatable' => TRUE);
00019     $options['choose'] = array('default' => '- Choose -', 'translatable' => TRUE);
00020     $options['default_value'] = array('default' => FALSE);
00021 
00022     return $options;
00023   }
00024 
00028   function options_form(&$form, &$form_state) {
00029     parent::options_form($form, $form_state);
00030     $handlers = $this->display->handler->get_handlers('field');
00031     if (empty($handlers)) {
00032       $form['error_markup'] = array(
00033         '#markup' => t('You need at least one field before you can configure your jump menu settings'),
00034         '#prefix' => '<div class="error messages">',
00035         '#suffix' => '</div>',
00036       );
00037       return;
00038     }
00039 
00040     $form['markup'] = array(
00041       '#markup' => t('To properly configure a jump menu, you must select one field that will represent the path to utilize. You should then set that field to exclude. All other displayed fields will be part of the menu. Please note that all HTML will be stripped from this output as select boxes cannot show HTML.'),
00042       '#prefix' => '<div class="form-item description">',
00043       '#suffix' => '</div>',
00044     );
00045 
00046     foreach ($handlers as $id => $handler) {
00047       $options[$id] = $handler->ui_name();
00048     }
00049 
00050     $form['path'] = array(
00051       '#type' => 'select',
00052       '#title' => t('Path field'),
00053       '#options' => $options,
00054       '#default_value' => $this->options['path'],
00055     );
00056 
00057     $form['hide'] = array(
00058       '#type' => 'checkbox',
00059       '#title' => t('Hide the "Go" button'),
00060       '#default_value' => !empty($this->options['hide']),
00061       '#description' => t('If hidden, this button will only be hidden for users with javascript and the page will automatically jump when the select is changed.'),
00062     );
00063 
00064     $form['text'] = array(
00065       '#type' => 'textfield',
00066       '#title' => t('Button text'),
00067       '#default_value' => $this->options['text'],
00068     );
00069 
00070     $form['choose'] = array(
00071       '#type' => 'textfield',
00072       '#title' => t('Choose text'),
00073       '#default_value' => $this->options['choose'],
00074       '#description' => t('The text that will appear as the selected option in the jump menu.'),
00075     );
00076 
00077     $form['default_value'] = array(
00078       '#type' => 'checkbox',
00079       '#title' => t('Select the current contextual filter value'),
00080       '#default_value' => !empty($this->options['default_value']),
00081       '#description' => t('If checked, the current path will be displayed as the default option in the jump menu, if applicable.'),
00082     );
00083   }
00084 
00090   function render() {
00091     $sets = $this->render_grouping($this->view->result, $this->options['grouping']);
00092 
00093     // Turn this all into an $options array for the jump menu.
00094     $this->view->row_index = 0;
00095     $options = array();
00096     $paths = array();
00097 
00098     foreach ($sets as $title => $records) {
00099       foreach ($records as $row_index => $row) {
00100         $this->view->row_index = $row_index;
00101         $path = strip_tags(decode_entities($this->get_field($this->view->row_index, $this->options['path'])));
00102         // Putting a '/' in front messes up url() so let's take that out
00103         // so users don't shoot themselves in the foot.
00104         $base_path = base_path();
00105         if (strpos($path, $base_path) === 0) {
00106           $path = drupal_substr($path, drupal_strlen($base_path));
00107         }
00108 
00109         // use drupal_parse_url() to preserve query and fragment in case the user
00110         // wants to do fun tricks.
00111         $url_options = drupal_parse_url($path);
00112 
00113         $path = url($url_options['path'], $url_options);
00114         $field = strip_tags(decode_entities($this->row_plugin->render($row)));
00115         $key = md5($path . $field) . "::" . $path;
00116         if ($title) {
00117           $options[$title][$key] = $field;
00118         }
00119         else {
00120           $options[$key] = $field;
00121         }
00122         $paths[$path] = $key;
00123         $this->view->row_index++;
00124       }
00125     }
00126     unset($this->view->row_index);
00127 
00128     $default_value = '';
00129     if ($this->options['default_value'] && !empty($paths[url($_GET['q'])])) {
00130       $default_value = $paths[url($_GET['q'])];
00131     }
00132 
00133     ctools_include('jump-menu');
00134     $settings = array(
00135       'hide' => $this->options['hide'],
00136       'button' => $this->options['text'],
00137       'choose' => $this->options['choose'],
00138       'default_value' => $default_value,
00139     );
00140 
00141     $form = drupal_get_form('ctools_jump_menu', $options, $settings);
00142     return $form;
00143   }
00144 
00145   function render_set($title, $records) {
00146     $options = array();
00147     $fields = $this->rendered_fields;
00148   }
00149 }

Generated on Sun Feb 26 2012 12:52:52 for Views by  doxygen 1.7.1