views_autocomplete_filters.module in Views Autocomplete Filters 6
File
views_autocomplete_filters.module
View source
<?php
function views_autocomplete_filters_menu() {
$items = array();
$items['autocomplete_filter'] = array(
'title' => 'Autocomplete Filters',
'page callback' => 'views_autocomplete_filter',
'access arguments' => array(
'access content',
),
'file' => 'views_autocomplete_filters.inc',
'type' => MENU_CALLBACK,
);
return $items;
}
function views_autocomplete_filters_selective_views_api() {
return array(
'api' => 2.0,
);
}
function views_autocomplete_filters_form_views_exposed_form_alter(&$form, $form_state) {
foreach ($form_state['view']->filter as $field => $filter) {
if ($filter->options['exposed']) {
if (isset($filter->options['expose']['autocomplete_filter'])) {
unset($form[$field_id]['#default_value']);
$field_id = $form['#info']["filter-{$field}"]['value'];
$form[$field_id]['#autocomplete_path'] = 'autocomplete_filter/' . $field . '/' . $form_state['view']->name . '/' . $form_state['view']->current_display;
}
}
}
}
function views_autocomplete_filters_form_views_ui_config_item_form_alter(&$form, $form_state) {
if ('2' != substr(views_api_version(), 0, 1)) {
return;
}
if ($form['options']['value']['#type'] != 'textfield') {
return;
}
if (empty($form['options']['expose'])) {
return;
}
$default['autocomplete_filter'] = empty($form_state['handler']->options['expose']['autocomplete_filter']) ? FALSE : $form_state['handler']->options['expose']['autocomplete_filter'];
$left = array();
$left['autocomplete_filter'] = array(
'#type' => 'checkbox',
'#title' => t('Use Autocomplete'),
'#default_value' => $default['autocomplete_filter'],
'#description' => t('Use Autocomplete for this filter.'),
);
$expose = $form['options']['expose'];
$first_chunk = array_splice($expose, 0, array_search('end_left', array_keys($expose)));
$form['options']['expose'] = array_merge($first_chunk, $left, $expose);
}