1 |
85ad3d82
|
Assos Assos
|
<?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 |
|
|
function option_definition() {
|
16 |
|
|
$options = parent::option_definition();
|
17 |
|
|
|
18 |
|
|
$options['text_input_required'] = array('default' => 'Select any filter and click on Apply to see results', 'translatable' => TRUE);
|
19 |
|
|
$options['text_input_required_format'] = array('default' => NULL);
|
20 |
|
|
return $options;
|
21 |
|
|
}
|
22 |
|
|
|
23 |
|
|
function options_form(&$form, &$form_state) {
|
24 |
|
|
parent::options_form($form, $form_state);
|
25 |
|
|
|
26 |
|
|
$form['text_input_required'] = array(
|
27 |
|
|
'#type' => 'text_format',
|
28 |
|
|
'#title' => t('Text on demand'),
|
29 |
|
|
'#description' => t('Text to display instead of results until the user selects and applies an exposed filter.'),
|
30 |
|
|
'#default_value' => $this->options['text_input_required'],
|
31 |
|
|
'#format' => isset($this->options['text_input_required_format']) ? $this->options['text_input_required_format'] : filter_default_format(),
|
32 |
|
|
'#wysiwyg' => FALSE,
|
33 |
|
|
);
|
34 |
|
|
}
|
35 |
|
|
|
36 |
|
|
function options_submit(&$form, &$form_state) {
|
37 |
|
|
$form_state['values']['exposed_form_options']['text_input_required_format'] = $form_state['values']['exposed_form_options']['text_input_required']['format'];
|
38 |
|
|
$form_state['values']['exposed_form_options']['text_input_required'] = $form_state['values']['exposed_form_options']['text_input_required']['value'];
|
39 |
|
|
parent::options_submit($form, $form_state);
|
40 |
|
|
}
|
41 |
|
|
|
42 |
|
|
function exposed_filter_applied() {
|
43 |
|
|
static $cache = NULL;
|
44 |
|
|
if (!isset($cache)) {
|
45 |
|
|
$view = $this->view;
|
46 |
|
|
if (is_array($view->filter) && count($view->filter)) {
|
47 |
|
|
foreach ($view->filter as $filter_id => $filter) {
|
48 |
|
|
if ($filter->is_exposed()) {
|
49 |
|
|
$identifier = $filter->options['expose']['identifier'];
|
50 |
|
|
if (isset($view->exposed_input[$identifier])) {
|
51 |
|
|
$cache = TRUE;
|
52 |
|
|
return $cache;
|
53 |
|
|
}
|
54 |
|
|
}
|
55 |
|
|
}
|
56 |
|
|
}
|
57 |
|
|
$cache = FALSE;
|
58 |
|
|
}
|
59 |
|
|
|
60 |
|
|
return $cache;
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
function pre_render($values) {
|
64 |
|
|
if (!$this->exposed_filter_applied()) {
|
65 |
|
|
$options = array(
|
66 |
|
|
'id' => 'area',
|
67 |
|
|
'table' => 'views',
|
68 |
|
|
'field' => 'area',
|
69 |
|
|
'label' => '',
|
70 |
|
|
'relationship' => 'none',
|
71 |
|
|
'group_type' => 'group',
|
72 |
|
|
'content' => $this->options['text_input_required'],
|
73 |
|
|
'format' => $this->options['text_input_required_format'],
|
74 |
6eb8d15f
|
Assos Assos
|
'empty' => TRUE,
|
75 |
85ad3d82
|
Assos Assos
|
);
|
76 |
|
|
$handler = views_get_handler('views', 'area', 'area');
|
77 |
|
|
$handler->init($this->view, $options);
|
78 |
|
|
$this->display->handler->handlers['empty'] = array(
|
79 |
|
|
'area' => $handler,
|
80 |
|
|
);
|
81 |
|
|
$this->display->handler->set_option('empty', array('text' => $options));
|
82 |
|
|
}
|
83 |
|
|
}
|
84 |
|
|
|
85 |
|
|
function query() {
|
86 |
|
|
if (!$this->exposed_filter_applied()) {
|
87 |
|
|
// We return with no query; this will force the empty text.
|
88 |
|
|
$this->view->built = TRUE;
|
89 |
|
|
$this->view->executed = TRUE;
|
90 |
|
|
$this->view->result = array();
|
91 |
|
|
}
|
92 |
|
|
else {
|
93 |
|
|
parent::query();
|
94 |
|
|
}
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
} |