forms.inc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. <?php
  2. /**
  3. * @file
  4. * Search forms
  5. */
  6. /**
  7. * Default admin form.
  8. */
  9. function _custom_search_default_admin_form($delta = '') {
  10. if ($delta != '') {
  11. $delta = 'blocks_' . $delta . '_';
  12. }
  13. // Labels & default text.
  14. $form['search_box'] = array(
  15. '#type' => 'fieldset',
  16. '#title' => t('Search box'),
  17. );
  18. $form['search_box']['custom_search_' . $delta . 'label_visibility'] = array(
  19. '#type' => 'checkbox',
  20. '#title' => t('Display label'),
  21. '#default_value' => variable_get('custom_search_' . $delta . 'label_visibility', TRUE),
  22. );
  23. $form['search_box']['custom_search_' . $delta . 'label'] = array(
  24. '#type' => 'textfield',
  25. '#title' => t('Search box label'),
  26. '#default_value' => variable_get('custom_search_' . $delta . 'label', CUSTOM_SEARCH_LABEL_DEFAULT),
  27. '#description' => t('Enter the label text for the search box. The default value is "!default".', array('!default' => CUSTOM_SEARCH_LABEL_DEFAULT)),
  28. '#states' => array(
  29. 'visible' => array(
  30. ':input[name="custom_search_' . $delta . 'label_visibility"]' => array('checked' => TRUE),
  31. ),
  32. ),
  33. );
  34. $form['search_box']['custom_search_' . $delta . 'text'] = array(
  35. '#type' => 'textfield',
  36. '#title' => t('Search box placeholder text'),
  37. '#default_value' => variable_get('custom_search_' . $delta . 'text', ''),
  38. '#description' => t('This will change the default text inside the search form. This is the <a href="http://www.w3schools.com/tags/att_input_placeholder.asp" target="_blank">placeholder</a> attribute for the TextField. Leave blank for no text. This field is blank by default.'),
  39. );
  40. $form['search_box']['custom_search_' . $delta . 'hint_text'] = array(
  41. '#type' => 'textfield',
  42. '#title' => t('Search box hint text'),
  43. '#default_value' => variable_get('custom_search_' . $delta . 'hint_text', CUSTOM_SEARCH_HINT_TEXT_DEFAULT),
  44. '#description' => t('Enter the text that will be displayed when hovering the input field (HTML <em>title</em> attritube).'),
  45. );
  46. if (module_exists('elements')) {
  47. $form['search_box']['custom_search_' . $delta . 'element'] = array(
  48. '#type' => 'select',
  49. '#title' => t('Search box input type'),
  50. '#options' => array(
  51. 'textfield' => 'text',
  52. 'searchfield' => 'search (HTML5)',
  53. ),
  54. '#default_value' => variable_get('custom_search_' . $delta . 'element', 'textfield'),
  55. '#description' => t('The default value is "text".'),
  56. );
  57. }
  58. $form['search_box']['custom_search_' . $delta . 'size'] = array(
  59. '#type' => 'textfield',
  60. '#title' => t('Search box size'),
  61. '#size' => 3,
  62. '#default_value' => variable_get('custom_search_' . $delta . 'size', CUSTOM_SEARCH_SIZE_DEFAULT),
  63. '#description' => t('The default value is "!default".', array('!default' => CUSTOM_SEARCH_SIZE_DEFAULT)),
  64. );
  65. $form['search_box']['custom_search_' . $delta . 'max_length'] = array(
  66. '#type' => 'textfield',
  67. '#title' => t('Search box maximum length'),
  68. '#size' => 3,
  69. '#default_value' => variable_get('custom_search_' . $delta . 'max_length', CUSTOM_SEARCH_MAX_LENGTH_DEFAULT),
  70. '#description' => t('The default value is "!default".', array('!default' => CUSTOM_SEARCH_MAX_LENGTH_DEFAULT)),
  71. '#required' => TRUE,
  72. );
  73. // Submit button.
  74. $form['submit_button'] = array(
  75. '#type' => 'fieldset',
  76. '#title' => t('Submit button'),
  77. );
  78. $form['submit_button']['custom_search_' . $delta . 'submit_text'] = array(
  79. '#type' => 'textfield',
  80. '#title' => t('Submit button text'),
  81. '#default_value' => variable_get('custom_search_' . $delta . 'submit_text', CUSTOM_SEARCH_SUBMIT_TEXT_DEFAULT),
  82. '#description' => t('Enter the text for the submit button. Leave blank to hide it. The default value is "!default".', array('!default' => CUSTOM_SEARCH_SUBMIT_TEXT_DEFAULT)),
  83. );
  84. $form['submit_button']['custom_search_' . $delta . 'image_path'] = array(
  85. '#type' => 'textfield',
  86. '#title' => t('Submit image path'),
  87. '#description' => t('The path to the file you would like to use as submit button instead of the default text button.'),
  88. '#default_value' => variable_get('custom_search_' . $delta . 'image_path', ''),
  89. );
  90. $form['submit_button']['custom_search_image'] = array(
  91. '#type' => 'file',
  92. '#title' => t('Submit image'),
  93. '#description' => t("If you don't have direct file access to the server, use this field to upload your image."),
  94. );
  95. // Criteria.
  96. $form['criteria'] = array(
  97. '#type' => 'fieldset',
  98. '#title' => t('Advanced search criteria'),
  99. '#collapsible' => TRUE,
  100. '#collapsed' => TRUE,
  101. );
  102. $form['criteria']['or'] = array(
  103. '#type' => 'fieldset',
  104. '#title' => t('Or'),
  105. );
  106. $form['criteria']['or']['custom_search_' . $delta . 'criteria_or_display'] = array(
  107. '#type' => 'checkbox',
  108. '#title' => t('Display'),
  109. '#default_value' => variable_get('custom_search_' . $delta . 'criteria_or_display', FALSE),
  110. );
  111. $form['criteria']['or']['custom_search_' . $delta . 'criteria_or_label'] = array(
  112. '#type' => 'textfield',
  113. '#title' => t('Label'),
  114. '#default_value' => variable_get('custom_search_' . $delta . 'criteria_or_label', CUSTOM_SEARCH_CRITERIA_OR_LABEL_DEFAULT),
  115. '#description' => t('Enter the label text for this field. The default value is "!default".', array('!default' => CUSTOM_SEARCH_CRITERIA_OR_LABEL_DEFAULT)),
  116. '#states' => array(
  117. 'visible' => array(
  118. ':input[name="custom_search_' . $delta . 'criteria_or_display"]' => array('checked' => TRUE),
  119. ),
  120. ),
  121. );
  122. $form['criteria']['phrase'] = array(
  123. '#type' => 'fieldset',
  124. '#title' => t('Phrase'),
  125. );
  126. $form['criteria']['phrase']['custom_search_' . $delta . 'criteria_phrase_display'] = array(
  127. '#type' => 'checkbox',
  128. '#title' => t('Display'),
  129. '#default_value' => variable_get('custom_search_' . $delta . 'criteria_phrase_display', FALSE),
  130. );
  131. $form['criteria']['phrase']['custom_search_' . $delta . 'criteria_phrase_label'] = array(
  132. '#type' => 'textfield',
  133. '#title' => t('Label'),
  134. '#default_value' => variable_get('custom_search_' . $delta . 'criteria_phrase_label', CUSTOM_SEARCH_CRITERIA_PHRASE_LABEL_DEFAULT),
  135. '#description' => t('Enter the label text for this field. The default value is "!default".', array('!default' => CUSTOM_SEARCH_CRITERIA_PHRASE_LABEL_DEFAULT)),
  136. '#states' => array(
  137. 'visible' => array(
  138. ':input[name="custom_search_' . $delta . 'criteria_phrase_display"]' => array('checked' => TRUE),
  139. ),
  140. ),
  141. );
  142. $form['criteria']['negative'] = array(
  143. '#type' => 'fieldset',
  144. '#title' => t('Negative'),
  145. );
  146. $form['criteria']['negative']['custom_search_' . $delta . 'criteria_negative_display'] = array(
  147. '#type' => 'checkbox',
  148. '#title' => t('Display'),
  149. '#default_value' => variable_get('custom_search_' . $delta . 'criteria_negative_display', FALSE),
  150. );
  151. $form['criteria']['negative']['custom_search_' . $delta . 'criteria_negative_label'] = array(
  152. '#type' => 'textfield',
  153. '#title' => t('Label'),
  154. '#default_value' => variable_get('custom_search_' . $delta . 'criteria_negative_label', CUSTOM_SEARCH_CRITERIA_NEGATIVE_LABEL_DEFAULT),
  155. '#description' => t('Enter the label text for this field. The default value is "!default".', array('!default' => CUSTOM_SEARCH_CRITERIA_NEGATIVE_LABEL_DEFAULT)),
  156. '#states' => array(
  157. 'visible' => array(
  158. ':input[name="custom_search_' . $delta . 'criteria_negative_display"]' => array('checked' => TRUE),
  159. ),
  160. ),
  161. );
  162. if (module_exists('search_api_page')) {
  163. $search_api_pages = search_api_page_load_multiple();
  164. $options[0] = t('None');
  165. foreach ($search_api_pages as $page) {
  166. $options[$page->id] = $page->name;
  167. }
  168. $form['searchapi'] = array(
  169. '#type' => 'fieldset',
  170. '#title' => t('Search API'),
  171. '#collapsible' => TRUE,
  172. '#collapsed' => TRUE,
  173. );
  174. $form['searchapi']['custom_search_' . $delta . 'search_api_page'] = array(
  175. '#type' => 'select',
  176. '#title' => t('Search API Page to use'),
  177. '#options' => $options,
  178. '#default_value' => variable_get('custom_search_' . $delta . 'search_api_page', 0),
  179. );
  180. }
  181. return $form;
  182. }
  183. /**
  184. * Content admin form.
  185. */
  186. function _custom_search_content_admin_form($delta = '') {
  187. if ($delta != '') {
  188. $delta = 'blocks_' . $delta . '_';
  189. }
  190. $form['content_selector'] = array(
  191. '#type' => 'fieldset',
  192. '#title' => t('Content selector'),
  193. '#description' => t("Select the search types to present as search options in the search block. If none is selected, no selector will be displayed. <strong>Note</strong>: if there's only one type checked, the selector won't be displayed BUT only this type will be searched."),
  194. );
  195. $form['content_selector']['custom_search_' . $delta . 'node_types'] = array(
  196. '#type' => 'checkboxes',
  197. '#title' => t('Content types'),
  198. '#default_value' => variable_get('custom_search_' . $delta . 'node_types', array()),
  199. '#options' => node_type_get_names(),
  200. );
  201. // Other searches.
  202. $options = array();
  203. foreach (module_implements('search_info') as $module) {
  204. if ($module != 'node' && $name = module_invoke($module, 'search_info')) {
  205. $options[$module] = $name['title'];
  206. }
  207. }
  208. if (count($options)) {
  209. $form['content_selector']['custom_search_' . $delta . 'other'] = array(
  210. '#type' => 'checkboxes',
  211. '#title' => t('Other searches'),
  212. '#default_value' => variable_get('custom_search_' . $delta . 'other', array()),
  213. '#options' => $options,
  214. );
  215. }
  216. $form['content_selector']['custom_search_' . $delta . 'type_selector'] = array(
  217. '#type' => 'select',
  218. '#title' => t('Selector type'),
  219. '#options' => array(
  220. 'select' => t('Drop-down list'),
  221. 'selectmultiple' => t('Drop-down list with multiple choices'),
  222. 'radios' => t('Radio buttons'),
  223. 'checkboxes' => t('Checkboxes'),
  224. ),
  225. '#description' => t('Choose which selector type to use. Note: content types and other searches cannot be combined in a single search.'),
  226. '#default_value' => variable_get('custom_search_' . $delta . 'type_selector', 'select'),
  227. );
  228. $form['content_selector']['custom_search_' . $delta . 'type_selector_label_visibility'] = array(
  229. '#type' => 'checkbox',
  230. '#title' => t('Display label'),
  231. '#default_value' => variable_get('custom_search_' . $delta . 'type_selector_label_visibility', TRUE),
  232. );
  233. $form['content_selector']['custom_search_' . $delta . 'type_selector_label'] = array(
  234. '#type' => 'textfield',
  235. '#title' => t('Label text'),
  236. '#default_value' => variable_get('custom_search_' . $delta . 'type_selector_label', CUSTOM_SEARCH_TYPE_SELECTOR_LABEL_DEFAULT),
  237. '#description' => t('Enter the label text for the selector. The default value is "!default".', array('!default' => CUSTOM_SEARCH_TYPE_SELECTOR_LABEL_DEFAULT)),
  238. '#states' => array(
  239. 'visible' => array(
  240. ':input[name="custom_search_' . $delta . 'type_selector_label_visibility"]' => array('checked' => TRUE),
  241. ),
  242. ),
  243. );
  244. $form['content_selector']['any'] = array(
  245. '#type' => 'fieldset',
  246. '#title' => t('-Any-'),
  247. );
  248. $form['content_selector']['any']['custom_search_' . $delta . 'type_selector_all'] = array(
  249. '#type' => 'textfield',
  250. '#title' => t('-Any content type- text'),
  251. '#default_value' => variable_get('custom_search_' . $delta . 'type_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT),
  252. '#required' => TRUE,
  253. '#description' => t('Enter the text for "any content type" choice. The default value is "!default".', array('!default' => CUSTOM_SEARCH_ALL_TEXT_DEFAULT)),
  254. );
  255. $form['content_selector']['any']['custom_search_' . $delta . 'any_restricts'] = array(
  256. '#type' => 'checkbox',
  257. '#title' => t('Choosing -Any- restricts the search to the selected content types.'),
  258. '#default_value' => variable_get('custom_search_' . $delta . 'any_restricts', FALSE),
  259. '#description' => t('If not checked, choosing -Any- will search in all content types.'),
  260. );
  261. $form['content_selector']['any']['custom_search_' . $delta . 'any_force'] = array(
  262. '#type' => 'checkbox',
  263. '#title' => t('Force -Any- to be displayed.'),
  264. '#default_value' => variable_get('custom_search_' . $delta . 'any_force', FALSE),
  265. '#description' => t('When only one content type is selected, the default behaviour is to hide the selector. If you need the -Any- option to be displayed, check this.'),
  266. );
  267. $form['custom_search_' . $delta . 'node_types_excluded'] = array(
  268. '#type' => 'checkboxes',
  269. '#title' => t('Content exclusion'),
  270. '#description' => t("Select the content types you don't want to be displayed as results.<br/><strong>Notice</strong>: content exclusion only works with the core Search module."),
  271. '#default_value' => variable_get('custom_search_' . $delta . 'node_types_excluded', array()),
  272. '#options' => node_type_get_names(),
  273. );
  274. return $form;
  275. }
  276. /**
  277. * Custom paths admin form.
  278. */
  279. function _custom_search_custom_paths_admin_form($delta = '') {
  280. if ($delta != '') {
  281. $delta = 'blocks_' . $delta . '_';
  282. }
  283. $form['custom_search_paths_admin'] = array(
  284. '#type' => 'fieldset',
  285. '#title' => t('Custom search paths'),
  286. '#collapsed' => TRUE,
  287. '#collapsible' => TRUE,
  288. );
  289. $form['custom_search_paths_admin']['custom_search_' . $delta . 'paths_selector'] = array(
  290. '#type' => 'select',
  291. '#title' => t('Selector type'),
  292. '#options' => array(
  293. 'select' => t('Drop-down list'),
  294. 'radios' => t('Radio buttons'),
  295. ),
  296. '#description' => t('Choose which selector type to use.'),
  297. '#default_value' => variable_get('custom_search_' . $delta . 'paths_selector', 'select'),
  298. );
  299. $form['custom_search_paths_admin']['custom_search_' . $delta . 'paths_selector_label_visibility'] = array(
  300. '#type' => 'checkbox',
  301. '#title' => t('Display label'),
  302. '#default_value' => variable_get('custom_search_' . $delta . 'paths_selector_label_visibility', TRUE),
  303. );
  304. $form['custom_search_paths_admin']['custom_search_' . $delta . 'paths_selector_label'] = array(
  305. '#type' => 'textfield',
  306. '#title' => t('Label text'),
  307. '#default_value' => variable_get('custom_search_' . $delta . 'paths_selector_label', CUSTOM_SEARCH_PATHS_SELECTOR_LABEL_DEFAULT),
  308. '#description' => t('Enter the label text for the selector. The default value is "!default".', array('!default' => CUSTOM_SEARCH_PATHS_SELECTOR_LABEL_DEFAULT)),
  309. );
  310. $form['custom_search_paths_admin']['custom_search_' . $delta . 'paths'] = array(
  311. '#type' => 'textarea',
  312. '#title' => t('Paths'),
  313. '#default_value' => variable_get('custom_search_' . $delta . 'paths', ''),
  314. '#rows' => 3,
  315. '#description' => t('If you want to use custom search paths, enter them here in the form <em>path</em>|<em>label</em>, one per line (if only one path is specified, the selector will be hidden). The [key] token will be replaced by what is entered in the search box. Ie: mysearch/[key]|My custom search label. The [current_path] token can be used to use the current URL path of the page beeing viewed.'),
  316. );
  317. return $form;
  318. }
  319. /**
  320. * Ordering admin form.
  321. */
  322. function _custom_search_ordering_admin_form($delta = '') {
  323. drupal_add_css(drupal_get_path('module', 'custom_search') . '/custom_search.css');
  324. if ($delta != '') {
  325. $delta = 'blocks_' . $delta . '_';
  326. }
  327. $form['order'] = array(
  328. '#type' => 'fieldset',
  329. '#title' => t('Elements ordering'),
  330. '#description' => t('Order the form elements as you want them to be displayed. If you put elements in the Popup section, they will only appear when the search field is clicked.'),
  331. );
  332. $form['order']['custom_search_' . $delta . 'order'] = array(
  333. '#tree' => TRUE,
  334. '#theme' => 'custom_search_sort_form',
  335. );
  336. $elements = array(
  337. 'search_box' => array('title' => t('Search box'), 'default_weight' => -1),
  338. 'criteria_or' => array('title' => t('Advanced search criterion: Or'), 'default_weight' => 6),
  339. 'criteria_phrase' => array('title' => t('Advanced search criterion: Phrase'), 'default_weight' => 7),
  340. 'criteria_negative' => array('title' => t('Advanced search criterion: Negative'), 'default_weight' => 8),
  341. 'custom_paths' => array('title' => t('Custom search paths'), 'default_weight' => 9),
  342. 'submit_button' => array('title' => t('Submit button'), 'default_weight' => 10),
  343. );
  344. if (count(array_filter(array_merge(variable_get('custom_search_' . $delta . 'node_types', array()), variable_get('custom_search_' . $delta . 'other', array()))))) {
  345. $elements['content_types'] = array('title' => t('Content Types'), 'default_weight' => 0);
  346. }
  347. foreach ($elements as $element => $data) {
  348. $form['order']['custom_search_' . $delta . 'order'][$element] = array(
  349. '#title' => $data['title'],
  350. '#weight' => variable_get('custom_search_' . $delta . $element . '_weight', $data['default_weight']),
  351. );
  352. $form['order']['custom_search_' . $delta . 'order'][$element]['sort'] = array(
  353. '#type' => 'weight',
  354. '#default_value' => variable_get('custom_search_' . $delta . $element . '_weight', $data['default_weight']),
  355. '#attributes' => array(
  356. 'class' => array(
  357. 'sort-select',
  358. 'sort-select-' . variable_get('custom_search_' . $delta . $element . '_region', 'block'),
  359. ),
  360. ),
  361. );
  362. $form['order']['custom_search_' . $delta . 'order'][$element]['region'] = array(
  363. '#type' => 'select',
  364. '#options' => array(
  365. 'block' => t('Block'),
  366. 'popup' => t('Popup'),
  367. ),
  368. '#default_value' => variable_get('custom_search_' . $delta . $element . '_region', 'block'),
  369. '#attributes' => array(
  370. 'class' => array(
  371. 'region-select',
  372. 'region-select-' . variable_get('custom_search_' . $delta . $element . '_region', 'block'),
  373. ),
  374. ),
  375. );
  376. }
  377. return $form;
  378. }