You are here

function custom_search_taxonomy_form_alter in Custom Search 7

Same name and namespace in other branches
  1. 6 modules/custom_search_taxonomy/custom_search_taxonomy.module \custom_search_taxonomy_form_alter()

Implements hook_form_alter().

File

modules/custom_search_taxonomy/custom_search_taxonomy.module, line 100
Bring customizations to the default search box

Code

function custom_search_taxonomy_form_alter(&$form, &$form_state, $form_id) {

  // Filter the form_id value to identify all the custom blocks.
  $form_id_processed = $form_id;
  $delta = '';
  for ($a = 1; $a <= variable_get('custom_search_blocks_number', 1); $a++) {
    if ($form_id == 'custom_search_blocks_form_' . $a) {
      $form_id_processed = 'custom_search_blocks_form';
      $delta = 'blocks_' . $a . '_';
    }
  }
  switch ($form_id_processed) {
    case 'block_admin_configure':
      if (isset($form['module']) && $form['module']['#value'] == 'custom_search_blocks') {
        $delta = $form['delta']['#value'];
        $vocabularies = taxonomy_get_vocabularies();
        if (count($vocabularies)) {
          $form['settings']['taxonomy'] = array(
            '#type' => 'fieldset',
            '#title' => t('Taxonomy'),
            '#description' => t('Select the vocabularies to present as search options in the search block. If none is selected, no selector will be displayed.'),
            '#collapsible' => TRUE,
          );

          // Get vocabularies forms.
          $form['settings']['taxonomy'] = _custom_search_taxonomy_admin_form($vocabularies, $delta);
          $form['settings']['order']['custom_search_blocks_' . $delta . '_order'] = array_merge($form['settings']['order']['custom_search_blocks_' . $delta . '_order'], _custom_search_taxonomy_sort_form($vocabularies, $delta));
          $collapsed = TRUE;
          foreach ($vocabularies as $voc) {
            if (variable_get('custom_search_blocks_' . $delta . '_voc' . $voc->vid . '_selector', 'disabled') != 'disabled') {
              $collapsed = FALSE;
            }
          }
          $form['settings']['taxonomy']['#collapsed'] = $collapsed;
        }
        $form['settings']['custom_search_paths_admin']['custom_search_blocks_' . $delta . '_paths']['#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, and the [terms] token will be replaced by the selected taxonomy term id(s). Ie: mysearch/[key]/[terms]|My custom search label.');
        $form['settings']['custom_search_paths_admin']['custom_search_blocks_' . $delta . '_paths_terms_separator'] = array(
          '#type' => 'textfield',
          '#title' => t('Taxonomy terms separator'),
          '#default_value' => variable_get('custom_search_blocks_' . $delta . '_paths_terms_separator', CUSTOM_SEARCH_PATHS_TERMS_SEPARATOR_DEFAULT),
          '#size' => 2,
        );
      }
      break;
    case 'custom_search_admin':
      $vocabularies = taxonomy_get_vocabularies();
      if (count($vocabularies)) {
        $form['order']['custom_search_order'] = array_merge($form['order']['custom_search_order'], _custom_search_taxonomy_sort_form($vocabularies));
      }
      $form['custom_search_paths_admin']['custom_search_paths']['#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, and the [terms] token will be replaced by the selected taxonomy term id(s). Ie: mysearch/[key]/[terms]|My custom search label.');
      $form['custom_search_paths_admin']['custom_search_paths_terms_separator'] = array(
        '#type' => 'textfield',
        '#title' => t('Taxonomy terms separator'),
        '#default_value' => variable_get('custom_search_paths_terms_separator', CUSTOM_SEARCH_PATHS_TERMS_SEPARATOR_DEFAULT),
        '#size' => 2,
      );
      break;
  }
}