function search_autocomplete_form_configure in Search Autocomplete 6.2
Same name and namespace in other branches
- 6.4 search_autocomplete.form.configure.inc \search_autocomplete_form_configure()
- 7.4 search_autocomplete.form.configure.inc \search_autocomplete_form_configure()
- 7.2 search_autocomplete.form.configure.inc \search_autocomplete_form_configure()
- 7.3 search_autocomplete.form.configure.inc \search_autocomplete_form_configure()
MENU CALLBACK: Define the form to configure the suggestions.
Return value
A rendered form
1 string reference to 'search_autocomplete_form_configure'
- search_autocomplete_menu in ./
search_autocomplete.admin.inc - Implementation of hook_menu(). Create an administration page to access admin form
File
- ./
search_autocomplete.form.configure.inc, line 20 - Search Autocomplete Helper functions to retrive suggestions from database
Code
function search_autocomplete_form_configure() {
$form = array();
$base = "admin/settings/search_autocomplete";
// base URL for this module configurations
// get data from database
$fid = arg(3);
$result_forms = db_query('SELECT * FROM {search_autocomplete_forms} WHERE fid = ' . $fid);
$item = db_fetch_array($result_forms);
$form['fid'] = array(
'#type' => 'hidden',
'#value' => $fid,
);
/* ------------------------------------------------------------------ */
// HOW - How to display Search Autocomplete suggestions
$form['search_autocomplete_how'] = array(
'#type' => 'fieldset',
'#title' => t('HOW - How to display Search Autocomplete suggestions?'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
// Number of characters before suggestions
$trigger = array();
for ($i = 1; $i < 20; $i++) {
$trigger[$i] = $i . ' ' . t('characters');
}
$form['search_autocomplete_how']['min_char'] = array(
'#type' => 'select',
'#title' => t('Minimum keyword size that uncouple autocomplete search'),
'#default_value' => $item['min_char'],
'#options' => $trigger,
'#multiple' => FALSE,
'#required' => TRUE,
);
// Number of suggestions to display
$limit = array();
for ($i = 1; $i < 50; $i++) {
$limit[$i] = $i . ' ' . t('results');
}
$form['search_autocomplete_how']['max_sug'] = array(
'#type' => 'select',
'#title' => t('Limit of the autocomplete search result'),
'#default_value' => $item['max_sug'],
'#options' => $limit,
'#multiple' => FALSE,
'#required' => TRUE,
);
/* ------------------------------------------------------------------ */
// WHAT - What to display in Search Autocomplete suggestions
$form['search_autocomplete_what'] = array(
'#type' => 'fieldset',
'#title' => t('WHAT - What to display in Search Autocomplete suggestions?'),
'#description' => t('Choose which data should be added to autocompletion suggestions.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#theme' => 'search_autocomplete_form_configuration_fieldset',
);
$form['search_autocomplete_what']['#tree'] = TRUE;
// Built possible suggestions
$result_suggestions = db_query('SELECT * FROM {search_autocomplete_suggestions} WHERE sug_fid = %d ORDER BY sug_weight ASC', $fid);
while ($suggestion = db_fetch_array($result_suggestions)) {
// if the module has no dependencies, or if the dependencies are enabled: activate the suggestion
if (drupal_strlen($suggestion['sug_dependencies']) == 0 || module_exists($suggestion['sug_dependencies'])) {
$activate = TRUE;
$title = $suggestion['sug_title'];
}
else {
$activate = FALSE;
$title = $suggestion['sug_title'] . ' ' . t('(require @module module)', array(
'@module' => $suggestion['sug_dependencies'],
));
}
$sid = $suggestion['sid'];
$form['search_autocomplete_what'][$sid]['sid'] = array(
'#type' => 'hidden',
'#value' => $sid,
'#disabled' => !$activate,
);
$form['search_autocomplete_what'][$sid]['sug_markup'] = array(
'#type' => 'markup',
'#value' => $title,
'#disabled' => !$activate,
);
$form['search_autocomplete_what'][$sid]['sug_title'] = array(
'#type' => 'hidden',
'#value' => $title,
'#disabled' => !$activate,
);
$form['search_autocomplete_what'][$sid]['sug_enabled'] = array(
'#type' => 'checkbox',
'#return_value' => 1,
'#default_value' => $suggestion['sug_enabled'],
'#disabled' => !$activate,
);
$form['search_autocomplete_what'][$sid]['sug_prefix'] = array(
// -> sug_prefix
'#type' => 'textfield',
'#default_value' => $suggestion['sug_prefix'],
'#maxlength' => 255,
'#size' => 35,
'#disabled' => !$activate,
);
$form['search_autocomplete_what'][$sid]['sug_weight'] = array(
// -> weight of the item in hierarchy
'#type' => 'weight',
'#default_value' => $suggestion['sug_weight'],
'#disabled' => !$activate,
);
$form['search_autocomplete_what'][$sid]['sug_edit'] = array(
// -> weight of the item in hierarchy
'#value' => l(t('edit'), "{$base}/suggestion/" . $suggestion['sid'] . "/edit"),
);
}
/* ------------------------------------------------------------------ */
// ADVANCED - Advanced options
$form['search_autocomplete_advanced'] = array(
'#type' => 'fieldset',
'#title' => t('ADVANCED - Advanced options'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['search_autocomplete_advanced']['selector'] = array(
'#type' => 'textfield',
'#title' => t('ID selector for this form'),
'#description' => t('Please change only if you know what you do, read <a href="http://projects.axiomcafe.fr/search-autocomplete">documentation</a> first.'),
'#default_value' => $item['selector'],
'#maxlength' => 255,
'#size' => 35,
);
// Add button validation
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
);
/* $form['reset'] = array(
'#type' => 'submit',
'#value' => t('Reset to defaults'),
'#submit' => array('submit_reset')
); */
return $form;
}