Projet

Général

Profil

Paste
Télécharger (3,32 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / plugins / views_plugin_exposed_form_input_required.inc @ 5d12d676

1
<?php
2

    
3
/**
4
 * @file
5
 * Definition of views_plugin_exposed_form_input_required.
6
 */
7

    
8
/**
9
 * Exposed form plugin that provides an exposed form with required input.
10
 *
11
 * @ingroup views_exposed_form_plugins
12
 */
13
class views_plugin_exposed_form_input_required extends views_plugin_exposed_form {
14

    
15
  /**
16
   * {@inheritdoc}
17
   */
18
  public function option_definition() {
19
    $options = parent::option_definition();
20

    
21
    $options['text_input_required'] = array('default' => 'Select any filter and click on Apply to see results', 'translatable' => TRUE);
22
    $options['text_input_required_format'] = array('default' => NULL);
23
    return $options;
24
  }
25

    
26
  /**
27
   * {@inheritdoc}
28
   */
29
  public function options_form(&$form, &$form_state) {
30
    parent::options_form($form, $form_state);
31

    
32
    $form['text_input_required'] = array(
33
      '#type' => 'text_format',
34
      '#title' => t('Text on demand'),
35
      '#description' => t('Text to display instead of results until the user selects and applies an exposed filter.'),
36
      '#default_value' => $this->options['text_input_required'],
37
      '#format' => isset($this->options['text_input_required_format']) ? $this->options['text_input_required_format'] : filter_default_format(),
38
      '#wysiwyg' => FALSE,
39
    );
40
  }
41

    
42
  /**
43
   * {@inheritdoc}
44
   */
45
  public function options_submit(&$form, &$form_state) {
46
    $form_state['values']['exposed_form_options']['text_input_required_format'] = $form_state['values']['exposed_form_options']['text_input_required']['format'];
47
    $form_state['values']['exposed_form_options']['text_input_required'] = $form_state['values']['exposed_form_options']['text_input_required']['value'];
48
    parent::options_submit($form, $form_state);
49
  }
50

    
51
  /**
52
   * {@inheritdoc}
53
   */
54
  public function exposed_filter_applied() {
55
    static $cache = NULL;
56
    if (!isset($cache)) {
57
      $view = $this->view;
58
      if (is_array($view->filter) && count($view->filter)) {
59
        foreach ($view->filter as $filter_id => $filter) {
60
          if ($filter->is_exposed()) {
61
            $identifier = $filter->options['expose']['identifier'];
62
            if (isset($view->exposed_input[$identifier])) {
63
              $cache = TRUE;
64
              return $cache;
65
            }
66
          }
67
        }
68
      }
69
      $cache = FALSE;
70
    }
71

    
72
    return $cache;
73
  }
74

    
75
  /**
76
   * {@inheritdoc}
77
   */
78
  public function pre_render($values) {
79
    if (!$this->exposed_filter_applied()) {
80
      $options = array(
81
        'id' => 'area',
82
        'table' => 'views',
83
        'field' => 'area',
84
        'label' => '',
85
        'relationship' => 'none',
86
        'group_type' => 'group',
87
        'content' => $this->options['text_input_required'],
88
        'format' => $this->options['text_input_required_format'],
89
        'empty' => TRUE,
90
      );
91
      $handler = views_get_handler('views', 'area', 'area');
92
      $handler->init($this->view, $options);
93
      $this->display->handler->handlers['empty'] = array(
94
        'area' => $handler,
95
      );
96
      $this->display->handler->set_option('empty', array('text' => $options));
97
    }
98
  }
99

    
100
  /**
101
   * {@inheritdoc}
102
   */
103
  public function query() {
104
    if (!$this->exposed_filter_applied()) {
105
      // We return with no query; this will force the empty text.
106
      $this->view->built = TRUE;
107
      $this->view->executed = TRUE;
108
      $this->view->result = array();
109
    }
110
    else {
111
      parent::query();
112
    }
113
  }
114

    
115
}