chosen.admin.inc 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. /**
  3. * @file
  4. * Chosen administration pages.
  5. */
  6. /**
  7. * Returns with the general configuration form.
  8. */
  9. function chosen_admin_settings($form, &$form_state) {
  10. $chosen_path = chosen_get_chosen_path();
  11. if (!$chosen_path) {
  12. drupal_set_message(t('The library could not be detected. You need to download the !chosen and extract the entire contents of the archive into the %path directory on your server.',
  13. array(
  14. '!chosen' => l(t('Chosen JavaScript file'), CHOSEN_WEBSITE_URL),
  15. '%path' => 'sites/all/libraries',
  16. )
  17. ), 'error');
  18. return;
  19. }
  20. $form['chosen_minimum_single'] = array(
  21. '#type' => 'select',
  22. '#title' => t('Minimum number of options for single select'),
  23. '#options' => array_merge(array('0' => t('Always apply')), drupal_map_assoc(range(1, 25))),
  24. '#default_value' => variable_get('chosen_minimum_single', 20),
  25. '#description' => t('The minimum number of options to apply Chosen for single select fields. Example : choosing 10 will only apply Chosen if the number of options is greater or equal to 10.'),
  26. );
  27. $form['chosen_minimum_multiple'] = array(
  28. '#type' => 'select',
  29. '#title' => t('Minimum number of options for multi select'),
  30. '#options' => array_merge(array('0' => t('Always apply')), drupal_map_assoc(range(1, 25))),
  31. '#default_value' => variable_get('chosen_minimum_multiple', 20),
  32. '#description' => t('The minimum number of options to apply Chosen for multi select fields. Example : choosing 10 will only apply Chosen if the number of options is greater or equal to 10.'),
  33. );
  34. $form['chosen_disable_search_threshold'] = array(
  35. '#type' => 'select',
  36. '#title' => t('Minimum number to show Search on Single Select'),
  37. '#options' => array_merge(array('0' => t('Never apply')), drupal_map_assoc(range(1, 25))),
  38. '#default_value' => variable_get('chosen_disable_search_threshold', 0),
  39. '#description' => t('The minimum number of options to apply Chosen search box. Example : choosing 10 will only apply Chosen search if the number of options is greater or equal to 10.'),
  40. );
  41. $form['chosen_minimum_width'] = array(
  42. '#type' => 'textfield',
  43. '#title' => t('Minimum width of widget'),
  44. '#field_suffix' => 'px',
  45. '#size' => 3,
  46. '#default_value' => variable_get('chosen_minimum_width', ''),
  47. '#description' => t('The minimum width of the Chosen widget. Leave blank to have chosen determine this.'),
  48. );
  49. $form['chosen_jquery_selector'] = array(
  50. '#type' => 'textarea',
  51. '#title' => t('Apply Chosen to the following elements'),
  52. '#description' => t('A comma-separated list of jQuery selectors to apply Chosen to, such as <code>select#edit-operation, select#edit-type</code> or <code>.chosen-select</code>. Defaults to <code>select</code> to apply Chosen to all <code>&lt;select&gt;</code> elements.'),
  53. '#default_value' => variable_get('chosen_jquery_selector', 'select:visible'),
  54. );
  55. $form['options'] = array(
  56. '#type' => 'fieldset',
  57. '#title' => t('Chosen general options'),
  58. );
  59. $form['options']['chosen_search_contains'] = array(
  60. '#type' => 'checkbox',
  61. '#title' => t('Search also in the middle of words'),
  62. '#default_value' => variable_get('chosen_search_contains', FALSE),
  63. '#description' => t('Per default chosen searches only at beginning of words. Enable this option will also find results in the middle of words.
  64. Example: Search for <em>land</em> will also find <code>Switzer<strong>land</strong></code>.'),
  65. );
  66. $form['options']['chosen_disable_search'] = array(
  67. '#type' => 'checkbox',
  68. '#title' => t('Disable search box'),
  69. '#default_value' => variable_get('chosen_disable_search', FALSE),
  70. '#description' => t('Enable or disable the search box in the results list to filter out possible options.'),
  71. );
  72. $form['theme_options'] = array(
  73. '#type' => 'fieldset',
  74. '#title' => t('Chosen per theme options'),
  75. );
  76. $form['theme_options']['chosen_disabled_themes'] = array(
  77. '#type' => 'checkboxes',
  78. '#title' => t('Disable the default Chosen theme for the following themes'),
  79. '#options' => _chosen_enabled_themes_options(),
  80. '#default_value' => variable_get('chosen_disabled_themes', array()),
  81. '#description' => t('Enable or disable the default Chosen CSS file. Select a theme if it contains custom styles for Chosen replacements.'),
  82. );
  83. $form['options']['chosen_include'] = array(
  84. '#type' => 'radios',
  85. '#title' => t('Use chosen for admin pages and/or front end pages'),
  86. '#options' => array(
  87. CHOSEN_INCLUDE_EVERYWHERE => t('Include Chosen on every page'),
  88. CHOSEN_INCLUDE_ADMIN => t('Include Chosen only on admin pages'),
  89. CHOSEN_INCLUDE_NO_ADMIN => t('Include Chosen only on front end pages'),
  90. ),
  91. '#default_value' => variable_get('chosen_include', CHOSEN_INCLUDE_EVERYWHERE),
  92. );
  93. $form['options']['chosen_allow_single_deselect'] = array(
  94. '#type' => 'checkbox',
  95. '#title' => t('Allow deselect on single selects'),
  96. '#default_value' => variable_get('chosen_allow_single_deselect', FALSE),
  97. '#description' => t("Enable or disable option deselection for single select fields. This will only work if the first option has blank text."),
  98. );
  99. $form['strings'] = array(
  100. '#type' => 'fieldset',
  101. '#title' => t('Chosen strings'),
  102. );
  103. $form['strings']['chosen_placeholder_text_multiple'] = array(
  104. '#type' => 'textfield',
  105. '#title' => t('Placeholder text of multiple selects'),
  106. '#required' => TRUE,
  107. '#default_value' => variable_get('chosen_placeholder_text_multiple', 'Choose some options'),
  108. );
  109. $form['strings']['chosen_placeholder_text_single'] = array(
  110. '#type' => 'textfield',
  111. '#title' => t('Placeholder text of single selects'),
  112. '#required' => TRUE,
  113. '#default_value' => variable_get('chosen_placeholder_text_single', 'Choose an option'),
  114. );
  115. $form['strings']['chosen_no_results_text'] = array(
  116. '#type' => 'textfield',
  117. '#title' => t('No results text'),
  118. '#required' => TRUE,
  119. '#default_value' => variable_get('chosen_no_results_text', 'No results match'),
  120. );
  121. return system_settings_form($form);
  122. }
  123. /**
  124. * Helper function to get options for enabled themes.
  125. */
  126. function _chosen_enabled_themes_options() {
  127. $options = array();
  128. // Get the list of themes.
  129. $themes = list_themes();
  130. foreach ($themes as $theme) {
  131. // Only create options for enabled themes.
  132. if ($theme->status) {
  133. $options[$theme->name] = $theme->info['name'];
  134. }
  135. }
  136. return $options;
  137. }