You are here

function facetapi_admin_settings_form in Facet API 6

Administrative settings for Search Lucene Facets.

Parameters

&$form_state: A keyed array containing the current state of the form.

$searcher: A string containing the machine readable name of the searcher module.

Return value

A FAPI array passed through system_settings_form().

2 string references to 'facetapi_admin_settings_form'
facetapi_apachesolr_menu in contrib/facetapi_apachesolr/facetapi_apachesolr.module
Implementation of hook_menu().
facetapi_luceneapi_menu in contrib/facetapi_luceneapi/facetapi_luceneapi.module
Implementation of hook_menu().

File

./facetapi.admin.inc, line 19
Administrative settings for Facet API modules.

Code

function facetapi_admin_settings_form(&$form_state, $searcher) {
  $form = array();

  // Stores necessary information.
  $form['#searcher'] = $searcher;
  $form['#type'] = facetapi_adapter_load($searcher)
    ->getType();
  $form['#realms'] = facetapi_realms_get();
  $form['#facets'] = facetapi_facets_get($searcher, $form['#type']);

  // Common url() function options that will redirect form submissions in linked
  // pages back to this form.
  $url_options = array(
    'query' => array(
      'destination' => $_GET['q'],
    ),
  );

  // Adds description, submit handler if there are facets.
  if (!empty($form['#facets'])) {
    $form['description']['#value'] = t('This page provides a drag-and-drop interface to enable certian facets in each realm and control the order they are shown on the page.  <em>Realms</em> are groups of facets that are displayed in a similar fashion on the search page. Since rendering is handled by the relam, a single facet may be displayed in different ways, for exmaple a form element or a list of clickable links. Like the core search, users need the <em>use advanced search</em> <a href="@permissions-page">permissions</a> to be able to use the facets.', array(
      '@permissions-page' => url('admin/user/permissions', $url_options),
    ));
  }

  // Iterates over realms, builds form for each realm.
  foreach ($form['#realms'] as $realm_name => $realm) {
    if (!empty($form['#facets'])) {

      // Sorts facets, builds options for checkbox.
      $options = array();
      $sorted_facets = $form['#facets'];
      facetapi_facets_sort($sorted_facets, $searcher, $realm_name);
      foreach ($sorted_facets as $facet_name => $facet) {
        $options[$facet_name] = '';
      }

      // Index settings fieldset.
      $form['facets'][$realm_name] = array(
        '#type' => 'fieldset',
        '#title' => t('Realm: @name', array(
          '@name' => $realm['title'],
        )),
        '#collapsible' => TRUE,
      );

      // Adds description of relam if one was provided.
      if (isset($realm['description'])) {
        $form['facets'][$realm_name]['#description'] = filter_xss($realm['description']);
      }

      // Adds facet checkboxes.
      $checkbox_var = sprintf('facetapi:facet_status:%s:%s', $searcher, $realm_name);
      $form['facets'][$realm_name]['table'][$checkbox_var] = array(
        '#type' => 'checkboxes',
        '#options' => $options,
        '#default_value' => variable_get($checkbox_var, array()),
      );

      // Adds facet weight dropboxes if relam is "sortable".
      if ($realm['sortable']) {
        foreach ($options as $facet_name => $title) {
          $weight_var = sprintf('facetapi:facet_weight:%s:%s:%s', $searcher, $realm_name, $facet_name);
          $form['weight'][$realm_name][$weight_var] = array(
            '#type' => 'weight',
            '#title' => '',
            '#delta' => 50,
            '#default_value' => variable_get($weight_var, 0),
            '#attributes' => array(
              'class' => 'facetapi-facet-weight',
            ),
          );
        }
      }

      // Adds "fieldset" specific option to expand fieldset if facets selected.
      if ('fieldset' == $realm_name) {
        $variable = sprintf('facetapi:expand_fieldset:%s:fieldset', $searcher);
        $form['facets'][$realm_name][$variable] = array(
          '#type' => 'checkbox',
          '#title' => t('Expand fieldset on faceted search'),
          '#default_value' => variable_get($variable, 1),
          '#description' => t('When facets are selected, the fieldset will remain expanded so users can more easily refine their search.'),
        );
      }
    }
    else {
      $form['facets'] = array(
        '#value' => t('No facets are available for this searcher.'),
      );
      return $form;
    }
  }

  // Finalizes the form and returns.
  $form = system_settings_form($form);
  $form['#theme'] = 'facetapi_admin_settings_form';
  $form['#submit'][] = 'facetapi_admin_settings_form_submit';
  return $form;
}