1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
*/
|
6
|
|
7
|
if (module_exists('search')) {
|
8
|
/**
|
9
|
* Plugins are described by creating a $plugin array which will be used
|
10
|
* by the system that includes this file.
|
11
|
*/
|
12
|
$plugin = array(
|
13
|
'single' => TRUE,
|
14
|
'title' => t('Advanced search form'),
|
15
|
'icon' => 'icon_search.png',
|
16
|
'description' => t('A search form with advanced options.'),
|
17
|
'required context' => new ctools_context_optional(t('Keywords'), 'string'),
|
18
|
'category' => t('Widgets'),
|
19
|
'defaults' => array(
|
20
|
'type' => 'node',
|
21
|
'form' => 'advanced',
|
22
|
'path_type' => 'default',
|
23
|
'path' => '',
|
24
|
'override_prompt' => FALSE,
|
25
|
'prompt' => '',
|
26
|
),
|
27
|
);
|
28
|
}
|
29
|
|
30
|
/**
|
31
|
* Render the custom content type.
|
32
|
*/
|
33
|
function ctools_search_form_content_type_render($subtype, $conf, $panel_args, $context) {
|
34
|
if (empty($context) || empty($context->data)) {
|
35
|
$keys = '';
|
36
|
}
|
37
|
else {
|
38
|
$keys = $context->data;
|
39
|
}
|
40
|
|
41
|
// Build the content type block.
|
42
|
$block = new stdClass();
|
43
|
$block->module = 'search';
|
44
|
$block->delta = 'form';
|
45
|
$block->title = '';
|
46
|
|
47
|
switch ($conf['path_type']) {
|
48
|
default:
|
49
|
case 'default':
|
50
|
$path = 'search/' . $conf['type'];
|
51
|
break;
|
52
|
case 'same':
|
53
|
$path = $_GET['q'];
|
54
|
$path = str_replace($keys, '', $path);
|
55
|
break;
|
56
|
|
57
|
case 'custom':
|
58
|
$path = $conf['path'];
|
59
|
break;
|
60
|
}
|
61
|
|
62
|
$prompt = $conf['override_prompt'] ? $conf['prompt'] : NULL;
|
63
|
|
64
|
$form_state = array(
|
65
|
'build_info' => array(
|
66
|
'args' => array($path, $keys, $conf['type'], $prompt),
|
67
|
),
|
68
|
);
|
69
|
|
70
|
module_load_include('inc', 'search', 'search.pages');
|
71
|
|
72
|
$block->content = drupal_build_form('search_form', $form_state);
|
73
|
if ($conf['form'] == 'simple' && isset($block->content['advanced'])) {
|
74
|
$block->content['advanced']['#access'] = FALSE;
|
75
|
}
|
76
|
|
77
|
return $block;
|
78
|
}
|
79
|
|
80
|
/**
|
81
|
* Returns an edit form for custom type settings.
|
82
|
*/
|
83
|
function ctools_search_form_content_type_edit_form($form, &$form_state) {
|
84
|
$conf = $form_state['conf'];
|
85
|
|
86
|
$types = array();
|
87
|
foreach (search_get_info() as $module => $info) {
|
88
|
$types[$module] = $info['title'];
|
89
|
}
|
90
|
|
91
|
$form['type'] = array(
|
92
|
'#type' => 'select',
|
93
|
'#title' => t('Search type'),
|
94
|
'#options' => $types,
|
95
|
'#default_value' => $conf['type'],
|
96
|
);
|
97
|
|
98
|
$form['form'] = array(
|
99
|
'#type' => 'select',
|
100
|
'#title' => t('Search form'),
|
101
|
'#options' => array(
|
102
|
'simple' => t('Simple'),
|
103
|
'advanced' => t('Advanced'),
|
104
|
),
|
105
|
'#default_value' => $conf['form'],
|
106
|
'#description' => t('The advanced form may have additional options based upon the search type. For example the advanced content (node) search form will allow searching by node type and taxonomy term.'),
|
107
|
);
|
108
|
|
109
|
$form['path_type'] = array(
|
110
|
'#prefix' => '<div class="container-inline">',
|
111
|
'#type' => 'select',
|
112
|
'#title' => t('Path'),
|
113
|
'#options' => array(
|
114
|
'default' => t('Default'),
|
115
|
'same' => t('Same page'),
|
116
|
'custom' => t('Custom'),
|
117
|
),
|
118
|
'#default_value' => $conf['path_type'],
|
119
|
);
|
120
|
|
121
|
$form['path'] = array(
|
122
|
'#type' => 'textfield',
|
123
|
'#default_value' => $conf['path'],
|
124
|
'#dependency' => array('edit-path-type' => array('custom')),
|
125
|
'#suffix' => '</div>',
|
126
|
);
|
127
|
|
128
|
$form['override_prompt'] = array(
|
129
|
'#prefix' => '<div class="container-inline">',
|
130
|
'#type' => 'checkbox',
|
131
|
'#default_value' => $conf['override_prompt'],
|
132
|
'#title' => t('Override default prompt'),
|
133
|
);
|
134
|
|
135
|
$form['prompt'] = array(
|
136
|
'#type' => 'textfield',
|
137
|
'#default_value' => $conf['prompt'],
|
138
|
'#dependency' => array('edit-override-prompt' => array(1)),
|
139
|
'#suffix' => '</div>',
|
140
|
);
|
141
|
return $form;
|
142
|
}
|
143
|
|
144
|
/**
|
145
|
* Submit handler for search form.
|
146
|
*/
|
147
|
function ctools_search_form_content_type_edit_form_submit($form, &$form_state) {
|
148
|
// Copy everything from our defaults.
|
149
|
foreach (array_keys($form_state['plugin']['defaults']) as $key) {
|
150
|
$form_state['conf'][$key] = $form_state['values'][$key];
|
151
|
}
|
152
|
}
|
153
|
|
154
|
/**
|
155
|
* Returns the administrative title for a type.
|
156
|
*/
|
157
|
function ctools_search_form_content_type_admin_title($subtype, $conf, $context) {
|
158
|
$info = search_get_info();
|
159
|
$type = isset($info[$conf['type']]['title']) ? $info[$conf['type']]['title'] : t('Missing/broken type');
|
160
|
return t('@type search form', array('@type' => $type));
|
161
|
}
|