handler_filter.inc in Sarnia 7
File
handlers/handler_filter.inc
View source
<?php
class SarniaViewsHandlerFilter extends SearchApiViewsHandlerFilter {
public function option_definition() {
$options = parent::option_definition();
$options['solr_property'] = array(
'default' => NULL,
);
$options['solr_property_expose'] = array(
'default' => FALSE,
);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['value']['#description'] = t('You can use tokens here.');
if (module_exists('token')) {
$form['token_list'] = array(
'#theme' => 'token_tree',
);
}
if ($this
->can_expose()) {
$form['solr_property_expose'] = array(
'#type' => 'checkbox',
'#title' => t('Expose Solr property selection'),
'#description' => t('Allow the user to choose the Solr property.'),
'#default_value' => $this->options['solr_property_expose'],
'#states' => array(
'enabled' => array(
':input[name="options[expose][use_operator]"]' => array(
'checked' => TRUE,
),
),
),
);
}
}
public function operator_form(&$form, &$form_state) {
parent::operator_form($form, $form_state);
if ($this->options['solr_property_expose'] || isset($form_state['form_id']) && $form_state['form_id'] == 'views_ui_config_item_form') {
$form['solr_property'] = array(
'#type' => 'select',
'#title' => t('Solr property'),
'#options' => sarnia_index_get_filter_options($this->definition['search_api_index']),
'#default_value' => $this->options['solr_property'],
);
sarnia_element_add_combobox($form['solr_property']);
}
}
function options_submit(&$form, &$form_state) {
parent::options_submit($form, $form_state);
$values =& $form_state['values']['options'];
$default_title = 'Solr property';
if (!isset($this->options['solr_property']) && $values['expose']['label'] == $default_title || $this->options['solr_property'] == $this->options['expose']['label'] && $this->options['expose']['label'] == $values['expose']['label']) {
$values['expose']['label'] = $values['solr_property'];
}
}
public function query() {
while (is_array($this->value)) {
$this->value = $this->value ? reset($this->value) : NULL;
}
$this->value = token_replace($this->value);
$this->real_field = $this->options['solr_property'];
parent::query();
}
function ui_name($short = FALSE) {
if (!empty($this->options['ui_name'])) {
$title = check_plain($this->options['ui_name']);
return $title;
}
$title = $short && isset($this->definition['title short']) ? $this->definition['title short'] : $this->definition['title'];
$title .= ': ' . $this->options['solr_property'];
if (!$short) {
$title = $this->definition['group'] . ': ' . $title;
}
return $title;
}
public function admin_summary() {
return check_plain($this->options['solr_property']) . ' ' . parent::admin_summary();
}
}