You are here

function theme_facetapi_admin_settings_form in Facet API 6

Themes the facet form into a draggable table.

Parameters

$form: A FAPI array containing a fieldset.

Return value

A themed form element.

File

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

Code

function theme_facetapi_admin_settings_form($form) {

  // Initializes table headers.
  $headers = array();
  $headers[] = array(
    'data' => t('Enabled'),
    'class' => 'checkbox',
  );
  $headers[] = t('Facet');
  $headers[] = t('Description');
  $headers[] = t('');
  $headers[] = t('Weight');

  // If there are facets defined for this module, adds them.
  foreach (element_children($form['facets']) as $realm_name) {
    $form['facets'][$realm_name]['table']['#value'] = '';
    $rows = array();

    // Iterates over facets, builds table rows.
    foreach (element_children($form['facets'][$realm_name]['table']) as $checkbox_var) {

      // Gets sorted facet names, iterates over facets to build rows.
      $facet_names = array_keys($form['facets'][$realm_name]['table'][$checkbox_var]['#options']);
      foreach ($facet_names as $facet_name) {
        $row = array();

        // Gets full facet definition from storage.
        $facet = $form['#facets'][$facet_name];

        // Builds out all rows except for the weight column.
        $row['data'] = array(
          array(
            'data' => drupal_render($form['facets'][$realm_name]['table'][$checkbox_var][$facet_name]),
            'class' => 'checkbox',
          ),
          array(
            'data' => check_plain($facet['title']),
          ),
          array(
            'data' => isset($facet['description']) ? filter_xss($facet['description']) : '',
          ),
          array(
            'data' => l(t('Configure'), sprintf('admin/settings/%s/facetapi/%s/%s', $form['#searcher'], $realm_name, $facet_name)),
          ),
        );

        // Adds weight column if realm is "sortable".
        if ($form['#realms'][$realm_name]['sortable']) {
          $weight_var = sprintf('facetapi:facet_weight:%s:%s:%s', $form['#searcher'], $realm_name, $facet_name);
          $row['class'] = 'draggable';
          $row['data'][] = array(
            'data' => drupal_render($form['weight'][$realm_name][$weight_var]),
            'class' => 'dropbox',
          );
        }

        // Appends the row.
        $rows[] = $row;
      }
    }

    // Builds the CSS ID for the table.
    $table_id = sprintf('facetapi-%s-%s-table', $form['#searcher'], $realm_name);

    // Adds tabledrag if sortable, otherwise removes weight header.
    $row_headers = $headers;
    if ($form['#realms'][$realm_name]['sortable']) {
      drupal_add_tabledrag($table_id, 'order', 'sibling', 'facetapi-facet-weight');
    }
    else {
      array_pop($row_headers);
    }

    // Themes the facet table.
    $form['facets'][$realm_name]['table']['#value'] .= theme('table', $row_headers, $rows, array(
      'id' => $table_id,
    ));
  }

  // Returns the form rendered as a table.
  return drupal_render($form);
}