public function SearchApiFacetapiAdapter::settingsForm in Search API 7
Allows for backend specific overrides to the settings form.
File
- contrib/
search_api_facetapi/ plugins/ facetapi/ adapter.inc, line 225 - Classes used by the Facet API module.
Class
- SearchApiFacetapiAdapter
- Facet API adapter for the Search API module.
Code
public function settingsForm(&$form, &$form_state) {
$facet = $form['#facetapi']['facet'];
$facet_settings = $this
->getFacet($facet)
->getSettings();
$options = $facet_settings->settings;
$search_ids = variable_get('search_api_facets_search_ids', array());
$search_ids = isset($search_ids[$this->info['instance']]) ? $search_ids[$this->info['instance']] : array();
if (count($search_ids) > 1) {
$form['global']['default_true'] = array(
'#type' => 'select',
'#title' => t('Display for searches'),
'#prefix' => '<div class="facetapi-global-setting">',
'#options' => array(
TRUE => t('For all except the selected'),
FALSE => t('Only for the selected'),
),
'#default_value' => isset($options['default_true']) ? $options['default_true'] : TRUE,
);
$form['global']['facet_search_ids'] = array(
'#type' => 'select',
'#title' => t('Search IDs'),
'#suffix' => '</div>',
'#options' => $search_ids,
'#size' => min(4, count($search_ids)),
'#multiple' => TRUE,
'#default_value' => isset($options['facet_search_ids']) ? $options['facet_search_ids'] : array(),
);
}
else {
$form['global']['default_true'] = array(
'#type' => 'value',
'#value' => TRUE,
);
$form['global']['facet_search_ids'] = array(
'#type' => 'value',
'#value' => array(),
);
}
// Add a granularity option to date query types.
if (isset($facet['query type']) && $facet['query type'] == 'date') {
$granularity_options = array(
FACETAPI_DATE_YEAR => t('Years'),
FACETAPI_DATE_MONTH => t('Months'),
FACETAPI_DATE_DAY => t('Days'),
FACETAPI_DATE_HOUR => t('Hours'),
FACETAPI_DATE_MINUTE => t('Minutes'),
FACETAPI_DATE_SECOND => t('Seconds'),
);
$form['global']['date_granularity'] = array(
'#type' => 'select',
'#title' => t('Granularity'),
'#description' => t('Determine the maximum drill-down level'),
'#prefix' => '<div class="facetapi-global-setting">',
'#suffix' => '</div>',
'#options' => $granularity_options,
'#default_value' => isset($options['date_granularity']) ? $options['date_granularity'] : FACETAPI_DATE_MINUTE,
);
$default_value = FACETAPI_DATE_YEAR;
if (isset($options['date_granularity_min'])) {
$default_value = $options['date_granularity_min'];
}
$form['global']['date_granularity_min'] = array(
'#type' => 'select',
'#title' => t('Minimum granularity'),
'#description' => t('Determine the minimum drill-down level to start at'),
'#prefix' => '<div class="facetapi-global-setting">',
'#suffix' => '</div>',
'#options' => $granularity_options,
'#default_value' => $default_value,
);
}
// Add an "Exclude" option for terms.
if (!empty($facet['query types']) && in_array('term', $facet['query types'])) {
$form['global']['operator']['#weight'] = -2;
unset($form['global']['operator']['#suffix']);
$form['global']['exclude'] = array(
'#type' => 'checkbox',
'#title' => t('Exclude'),
'#description' => t('Make the search exclude selected facets, instead of restricting it to them.'),
'#suffix' => '</div>',
'#weight' => -1,
'#default_value' => !empty($options['exclude']),
);
}
}