You are here

function apachesolr_enabled_facets_form in Apache Solr Search 6

Same name and namespace in other branches
  1. 5.2 apachesolr.admin.inc \apachesolr_enabled_facets_form()
  2. 6.2 apachesolr.admin.inc \apachesolr_enabled_facets_form()

Creates the form that allows the user to select which facets will be enabled.

Only enabled facets are sent to solr. Fewer enabled facets can reduce the load on the search server. Blocks are only offered for enabled facets, so this also reduces the clutter on the blocks admin page.

1 string reference to 'apachesolr_enabled_facets_form'
apachesolr_menu in ./apachesolr.module
Implementation of hook_menu().

File

./apachesolr.admin.inc, line 275
Administrative pages for the Apache Solr framework.

Code

function apachesolr_enabled_facets_form() {
  $facets = array();
  $module_facets = array();
  $module_list = array();
  foreach (module_implements('apachesolr_facets') as $module) {
    $module_facets[$module] = module_invoke($module, 'apachesolr_facets');
    uasort($module_facets[$module], '_apachesolr_sort_facets');
    $module_list[$module] = $module;
  }
  $enabled_facets = apachesolr_get_enabled_facets();
  $form = array();
  $form['apachesolr_enabled_facets']['help'] = array(
    '#type' => 'item',
    '#value' => t('You can use this screen to select which search filter blocks should be created by enabling the corresponding filters on this page. For performance reasons, you should only enable filters that you intend to have available to users on the search page.  After selecting which filter blocks to create, you will be sent to the blocks page where you can choose which of those blocks should be enabled when your users search by placing each block in a region.'),
  );
  if ($module_list) {
    $placeholders = implode(', ', array_fill(0, count($module_list), "'%s'"));
    $result = db_query("SELECT name, info FROM {system} WHERE name IN (" . $placeholders . ") AND type = 'module'", $module_list);
    while ($item = db_fetch_array($result)) {
      $module_list[$item['name']] = unserialize($item['info']);
    }
  }
  foreach ($module_facets as $module => $facets) {
    $form['apachesolr_enabled_facets'][$module] = array(
      '#type' => 'fieldset',
      '#title' => check_plain($module_list[$module]['name']),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
    );

    // We must use module + delta as the keys since that combination is
    // guaranteed to be unique.  A single module could, for example, have
    // two different blocks that expose different faceting on the same
    // field in the index.
    foreach ($facets as $delta => $data) {
      $form['apachesolr_enabled_facets'][$module][$delta] = array(
        '#type' => 'checkbox',
        '#title' => $data['info'],
        '#return_value' => $data['facet_field'],
        '#default_value' => isset($enabled_facets[$module][$delta]) ? $data['facet_field'] : 0,
      );
    }
  }
  $has_facets = (bool) $module_facets;
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
    '#access' => $has_facets,
  );
  $form['no-facets-message'] = array(
    '#value' => t('<em>No filters are available from your currently enabled modules</em>'),
    '#access' => !$has_facets,
  );
  $form['#tree'] = TRUE;
  $form['submit_message'] = array(
    '#type' => 'value',
    '#value' => t('The Apache Solr filters settings were changed.  To arrange the blocks for your enabled filters, visit the <a href="@url">blocks administration page</a>.', array(
      '@url' => url('admin/build/block'),
    )),
  );
  return $form;
}