[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/views/plugins/ -> views_plugin_style_jump_menu.inc (source)

   1  <?php
   2  /**
   3   * @file
   4   * Contains the table style plugin.
   5   */
   6  
   7  /**
   8   * Style plugin to render each item as a row in a table.
   9   *
  10   * @ingroup views_style_plugins
  11   */
  12  class views_plugin_style_jump_menu extends views_plugin_style {
  13    function option_definition() {
  14      $options = parent::option_definition();
  15  
  16      $options['hide'] = array('default' => FALSE);
  17      $options['path'] = array('default' => '');
  18      $options['text'] = array('default' => 'Go', 'translatable' => TRUE);
  19      $options['choose'] = array('default' => '- Choose -', 'translatable' => TRUE);
  20      $options['default_value'] = array('default' => FALSE);
  21  
  22      return $options;
  23    }
  24  
  25    /**
  26     * Render the given style.
  27     */
  28    function options_form(&$form, &$form_state) {
  29      parent::options_form($form, $form_state);
  30      $handlers = $this->display->handler->get_handlers('field');
  31      if (empty($handlers)) {
  32        $form['error_markup'] = array(
  33          '#value' => t('You need at least one field before you can configure your jump menu settings'),
  34          '#prefix' => '<div class="error form-item description">',
  35          '#suffix' => '</div>',
  36        );
  37        return;
  38      }
  39  
  40      $form['markup'] = array(
  41        '#value' => 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.'),
  42        '#prefix' => '<div class="form-item description">',
  43        '#suffix' => '</div>',
  44      );
  45  
  46      foreach ($handlers as $id => $handler) {
  47        $options[$id] = $handler->ui_name();
  48      }
  49  
  50      $form['path'] = array(
  51        '#type' => 'select',
  52        '#title' => t('Path field'),
  53        '#options' => $options,
  54        '#default_value' => $this->options['path'],
  55      );
  56  
  57      $form['hide'] = array(
  58        '#type' => 'checkbox',
  59        '#title' => t('Hide the "Go" button.'),
  60        '#default_value' => !empty($this->options['hide']),
  61        '#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.'),
  62      );
  63  
  64      $form['text'] = array(
  65        '#type' => 'textfield',
  66        '#title' => t('Button text'),
  67        '#default_value' => $this->options['text'],
  68      );
  69  
  70      $form['choose'] = array(
  71        '#type' => 'textfield',
  72        '#title' => t('Choose text'),
  73        '#default_value' => $this->options['choose'],
  74        '#description' => t('The text that will appear as the selected option in the jump menu.'),
  75      );
  76  
  77      $form['default_value'] = array(
  78        '#type' => 'checkbox',
  79        '#title' => t('Select the current argument.'),
  80        '#default_value' => !empty($this->options['default_value']),
  81        '#description' => t('If checked, the current path will be displayed as the default option in the jump menu, if applicable.'),
  82      );
  83    }
  84  
  85    /**
  86     * Render the display in this style.
  87     *
  88     * This is overridden so that we can render our grouping specially.
  89     */
  90    function render() {
  91      $sets = $this->render_grouping($this->view->result, $this->options['grouping']);
  92  
  93      // Turn this all into an $options array for the jump menu.
  94      $this->view->row_index = 0;
  95      $options = array();
  96      $paths = array();
  97  
  98      foreach ($sets as $title => $records) {
  99        foreach ($records as $row_index => $row) {
 100          $this->view->row_index = $row_index;
 101          $path = html_entity_decode(strip_tags($this->get_field($this->view->row_index, $this->options['path'])), ENT_QUOTES);
 102          // Putting a '/' in front messes up url() so let's take that out
 103          // so users don't shoot themselves in the foot.
 104          if (strpos($path, '/') === 0) {
 105            $path = substr($path, 1);
 106          }
 107  
 108          // use parse_url() to preserve query and fragment in case the user
 109          // wants to do fun tricks.
 110          $url = parse_url($path);
 111          $url_options = array();
 112          if (isset($url['query'])) {
 113            $path = strtr($path, array('?' . $url['query'] => ''));
 114            $url_options['query'] = $url['query'];
 115          }
 116          if (isset($url['fragment'])) {
 117            $path = strtr($path, array('#' . $url['fragment'] => ''));
 118            $url_options['fragment'] = $url['fragment'];
 119          }
 120  
 121          $path = url($path, $url_options);
 122          $field = html_entity_decode(strip_tags($this->row_plugin->render($row)), ENT_QUOTES);
 123          if ($title) {
 124            $options[$title][$path] = $field;
 125          }
 126          else {
 127            $options[$path] = $field;
 128          }
 129          $paths[$path] = $path;
 130          $this->view->row_index++;
 131        }
 132      }
 133      unset($this->view->row_index);
 134  
 135      $default_value = '';
 136      if ($this->options['default_value'] && !empty($paths[url($_GET['q'])])) {
 137        $default_value = url($_GET['q']);
 138      }
 139  
 140      ctools_include('jump-menu');
 141      $settings = array(
 142        'hide' => $this->options['hide'],
 143        'button' => $this->options['text'],
 144        'choose' => $this->options['choose'],
 145        'default_value' => $default_value,
 146      );
 147  
 148      return drupal_get_form('ctools_jump_menu', $options, $settings);
 149    }
 150  
 151    function render_set($title, $records) {
 152      $options = array();
 153      $fields = $this->rendered_fields;
 154    }
 155  }


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7