#1172714 by mstrelan: Allow to embed another display from the same view
[project/views.git] / plugins / views_plugin_exposed_form_input_required.inc
1 <?php
2
3 /**
4 * Exposed form plugin that provides basic exposed form
5 */
6 class views_plugin_exposed_form_input_required extends views_plugin_exposed_form {
7
8 function option_definition() {
9 $options = parent::option_definition();
10
11 $options['text_input_required'] = array('default' => t('Select any filter and click on Apply to see results'), 'translatable' => TRUE);
12 $options['text_input_required_format'] = array('default' => NULL);
13 return $options;
14 }
15
16 function options_form(&$form, &$form_state) {
17 parent::options_form($form, $form_state);
18
19 $form['text_input_required'] = array(
20 '#type' => 'text_format',
21 '#title' => t('Text on demand'),
22 '#description' => t('Text to display instead of results until the user selects and applies an exposed filter.'),
23 '#default_value' => $this->options['text_input_required'],
24 '#format' => isset($this->options['text_input_required_format']) ? $this->options['text_input_required_format'] : filter_default_format(),
25 '#wysiwyg' => FALSE,
26 );
27 }
28
29 function options_submit(&$form, &$form_state) {
30 $form_state['values']['exposed_form_options']['text_input_required_format'] = $form_state['values']['exposed_form_options']['text_input_required']['format'];
31 $form_state['values']['exposed_form_options']['text_input_required'] = $form_state['values']['exposed_form_options']['text_input_required']['value'];
32 parent::options_submit($form, $form_state);
33 }
34
35 function exposed_filter_applied() {
36 static $cache = NULL;
37 if (!isset($cache)) {
38 $view = $this->view;
39 if (is_array($view->filter) && count($view->filter)) {
40 foreach ($view->filter as $filter_id => $filter) {
41 if ($filter->is_exposed()) {
42 $identifier = $filter->options['expose']['identifier'];
43 if (isset($view->exposed_input[$identifier])) {
44 $cache = TRUE;
45 return $cache;
46 }
47 }
48 }
49 }
50 $cache = FALSE;
51 }
52
53 return $cache;
54 }
55
56 function pre_render($values) {
57 if (!$this->exposed_filter_applied()) {
58 $options = array(
59 'id' => 'area',
60 'table' => 'views',
61 'field' => 'area',
62 'label' => '',
63 'relationship' => 'none',
64 'group_type' => 'group',
65 'content' => $this->options['text_input_required'],
66 'format' => $this->options['text_input_required_format'],
67 );
68 $handler = views_get_handler('views', 'area', 'area');
69 $handler->init($this->view, $options);
70 $this->display->handler->handlers['empty'] = array(
71 'area' => $handler,
72 );
73 $this->display->handler->set_option('empty', array('text' => $options));
74 }
75 }
76
77 function query() {
78 if (!$this->exposed_filter_applied()) {
79 // We return with no query; this will force the empty text.
80 $this->view->built = TRUE;
81 $this->view->executed = TRUE;
82 $this->view->result = array();
83 }
84 else {
85 parent::query();
86 }
87 }
88
89 }