You are here

function facetapi_realm_settings_form in Facet API 7

Same name and namespace in other branches
  1. 6.3 facetapi.admin.inc \facetapi_realm_settings_form()
  2. 7.2 facetapi.admin.inc \facetapi_realm_settings_form()

Form constructor for the realm settings form.

Parameters

$searcher: The machine readable name of the searcher.

$realm_name: The machine readable name of the realm.

See also

facetapi_realm_settings_form_submit()

1 string reference to 'facetapi_realm_settings_form'
facetapi_menu in ./facetapi.module
Implements hook_menu().

File

./facetapi.admin.inc, line 32
Admin page callbacks for the Facet API module.

Code

function facetapi_realm_settings_form($form, &$form_state, $searcher, $realm_name) {

  // Instantiates adapter, loads realm.
  $adapter = facetapi_adapter_load($searcher);
  $realm = facetapi_realm_load($realm_name);
  $form['#facetapi'] = array(
    'adapter' => $adapter,
    'realm' => $realm,
    'facet_info' => facetapi_get_facet_info($searcher),
  );
  $form['description'] = array(
    '#prefix' => '<div class="facetapi-realm-description">',
    '#markup' => filter_xss_admin($realm['description']),
    '#suffix' => "</div>\n",
  );
  $form['performance'] = array(
    '#prefix' => '<div class="facetapi-performance-note">',
    '#markup' => t('For performance reasons, you should only enable facets that you intend to have available to users on the search page.'),
    '#suffix' => "</div>\n",
  );
  $form['table'] = array(
    '#theme' => 'facetapi_realm_settings_table',
    '#facetapi' => &$form['#facetapi'],
    'operations' => array(
      '#tree' => TRUE,
    ),
    'weight' => array(
      '#tree' => TRUE,
    ),
  );

  // Builds "enabled_facets" options.
  $options = $default_value = array();
  foreach ($form['#facetapi']['facet_info'] as $facet_name => $facet) {
    $settings = $adapter
      ->getFacetSettings($facet, $realm);
    $global_settings = $adapter
      ->getFacetSettingsGlobal($facet);

    // Builds array of operations to use in the dropbutton.
    $operations = array();
    $operations[] = array(
      'title' => t('Configure display'),
      'href' => facetapi_get_settings_path($searcher, $realm['name'], $facet_name, 'edit'),
    );
    if ($facet['dependency plugins']) {
      $operations[] = array(
        'title' => t('Configure dependencies'),
        'href' => facetapi_get_settings_path($searcher, $realm['name'], $facet_name, 'dependencies'),
      );
    }
    if (facetapi_filters_load($facet_name, $searcher, $realm['name'])) {
      $operations[] = array(
        'title' => t('Configure filters'),
        'href' => facetapi_get_settings_path($searcher, $realm['name'], $facet_name, 'filters'),
      );
    }
    $operations[] = array(
      'title' => t('Export configuration'),
      'href' => facetapi_get_settings_path($searcher, $realm['name'], $facet_name, 'export'),
    );
    if (facetapi_is_overridden($settings) || facetapi_is_overridden($global_settings)) {
      $operations[] = array(
        'title' => t('Revert configuration'),
        'href' => facetapi_get_settings_path($searcher, $realm['name'], $facet_name, 'revert'),
      );
    }
    $form['table']['operations'][$facet_name] = array(
      '#theme' => 'links__ctools_dropbutton',
      '#links' => $operations,
      '#attributes' => array(
        'class' => array(
          'inline',
          'links',
          'actions',
          'horizontal',
          'right',
        ),
      ),
    );

    // Adds weight if sortable.
    if ($realm['sortable']) {
      $form['#facetapi']['facet_info'][$facet_name]['weight'] = $settings->settings['weight'];
      $form['table']['weight'][$facet_name] = array(
        '#type' => 'select',
        '#title' => t('Weight for @title', array(
          '@title' => $facet['label'],
        )),
        '#title_display' => 'invisible',
        '#options' => drupal_map_assoc(range(-50, 50)),
        '#default_value' => $settings->settings['weight'],
        '#attributes' => array(
          'class' => array(
            'facetapi-facet-weight',
          ),
        ),
      );
    }
    $options[$facet_name] = '';
    $default_value[$facet_name] = !$settings->enabled ? 0 : $facet_name;
  }

  // Sorts by the weight appended above.
  uasort($form['#facetapi']['facet_info'], 'drupal_sort_weight');
  $form['table']['enabled_facets'] = array(
    '#type' => 'checkboxes',
    '#options' => $options,
    '#default_value' => $default_value,
  );

  // Checks whether block caching is enabled, sets description accordingly.
  if (!($disabled = module_implements('node_grants') || !variable_get('block_cache', FALSE))) {
    $description = t('Configure the appropriate cache setting for facet blocks.');
  }
  else {
    $description = t('To enable block caching, visit the <a href="@performance-page">performance page</a>.', array(
      '@performance-page' => url('admin/config/development/performance', array(
        'query' => array(
          'destination' => current_path(),
        ),
      )),
    ));
  }
  $form['block_cache'] = array(
    '#type' => 'select',
    '#access' => 'block' == $realm_name,
    '#title' => t('Block cache settings'),
    '#disabled' => $disabled,
    '#options' => array(
      DRUPAL_NO_CACHE => t('Do not cache'),
      DRUPAL_CACHE_PER_ROLE | DRUPAL_CACHE_PER_PAGE => t('Per role'),
      DRUPAL_CACHE_PER_USER | DRUPAL_CACHE_PER_PAGE => t('Per user'),
    ),
    '#default_value' => variable_get('facetapi:block_cache:' . $searcher, DRUPAL_NO_CACHE),
    '#description' => $description,
  );
  $form['actions'] = array(
    '#type' => 'actions',
    '#weight' => 20,
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );
  $form['#submit'][] = 'facetapi_realm_settings_form_submit';
  return $form;
}