| 1 |
|
<?php |
| 2 |
|
// $Id: views_plugin_exposed_form_basic.inc,v Exp $ |
| 3 |
|
|
| 4 |
|
/** |
| 5 |
|
* Exposed form plugin that provides basic exposed form |
| 6 |
|
*/ |
| 7 |
|
class views_plugin_exposed_form_input_required extends views_plugin_exposed_form { |
| 8 |
|
|
| 9 |
|
function summary_title() { |
| 10 |
|
return t('Input required'); |
| 11 |
|
} |
| 12 |
|
|
| 13 |
|
function option_definition() { |
| 14 |
|
$options = parent::option_definition(); |
| 15 |
|
|
| 16 |
|
$options['text_input_required'] = array('default' => t('Select any filter and click on Apply to see results'), 'translatable' => TRUE); |
| 17 |
|
$options['text_input_required_format'] = array('default' => FILTER_FORMAT_DEFAULT); |
| 18 |
|
return $options; |
| 19 |
|
} |
| 20 |
|
|
| 21 |
|
function options_form(&$form, &$form_state) { |
| 22 |
|
parent::options_form($form, $form_state); |
| 23 |
|
|
| 24 |
|
$form['text_input_required'] = array( |
| 25 |
|
'#type' => 'textarea', |
| 26 |
|
'#title' => t('Text on demand'), |
| 27 |
|
'#description' => t('Text to display instead results until user select and apply an expose filter.'), |
| 28 |
|
'#default_value' => $this->options['text_input_required'], |
| 29 |
|
); |
| 30 |
|
|
| 31 |
|
$form['text_input_required_format'] = filter_form($this->options['text_input_required_format'], NULL, array('text_input_required_format')); |
| 32 |
|
} |
| 33 |
|
|
| 34 |
|
function options_submit(&$form, &$form_state) { |
| 35 |
|
$form_state['values']['exposed_form_options']['text_input_required_format'] = $form_state['values']['text_input_required_format']; |
| 36 |
|
|
| 37 |
|
parent::options_submit($form, $form_state); |
| 38 |
|
} |
| 39 |
|
|
| 40 |
|
function exposed_filter_applied() { |
| 41 |
|
static $cache = NULL; |
| 42 |
|
if (!isset($cache)) { |
| 43 |
|
$view = $this->view; |
| 44 |
|
$exposed_data = $view->exposed_data; |
| 45 |
|
if (is_array($view->filter) && count($view->filter)) { |
| 46 |
|
foreach ($view->filter as $filter_id => $filter) { |
| 47 |
|
if ($filter->is_exposed()) { |
| 48 |
|
$identifier = $filter->options['expose']['identifier']; |
| 49 |
|
if (isset($view->exposed_input[$identifier])) { |
| 50 |
|
$cache = TRUE; |
| 51 |
|
return $cache; |
| 52 |
|
} |
| 53 |
|
} |
| 54 |
|
} |
| 55 |
|
} |
| 56 |
|
$cache = FALSE; |
| 57 |
|
} |
| 58 |
|
|
| 59 |
|
return $cache; |
| 60 |
|
} |
| 61 |
|
|
| 62 |
|
function pre_render() { |
| 63 |
|
if (!$this->exposed_filter_applied()) { |
| 64 |
|
$this->view->display_handler->set_option('empty', $this->options['text_input_required']); |
| 65 |
|
$this->view->display_handler->set_option('empty_format', $this->options['text_input_required_format']); |
| 66 |
|
} |
| 67 |
|
} |
| 68 |
|
|
| 69 |
|
function query() { |
| 70 |
|
if (!$this->exposed_filter_applied()) { |
| 71 |
|
// We return with no query; this will force the empty text. |
| 72 |
|
$this->view->built = TRUE; |
| 73 |
|
$this->view->executed = TRUE; |
| 74 |
|
$this->view->result = array(); |
| 75 |
|
} |
| 76 |
|
} |
| 77 |
|
|
| 78 |
|
} |