data_search.admin.inc in Data 6
File
data_search/data_search.admin.inc
View source
<?php
function data_search_admin_form(&$form_state, $table) {
drupal_set_title(check_plain($table
->get('title')));
$schema = $table
->get('table_schema');
$meta = $table
->get('meta');
$form = array();
if (count($schema['primary key']) != 1) {
drupal_set_message(t('Only tables with a single-field primary key can be indexed.'), 'error');
return $form;
}
$form['#table'] = $table;
$form['fields'] = array(
'#tree' => TRUE,
);
if (isset($schema['fields'])) {
$enabled_fields = data_search_get_fields($table);
foreach ($schema['fields'] as $field_name => $field) {
$form['fields'][$field_name] = array();
$form['fields'][$field_name]['name'] = array(
'#value' => $field_name,
);
$form['fields'][$field_name]['search'] = array(
'#type' => 'checkbox',
'#default_value' => in_array($field_name, $enabled_fields),
);
}
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
function data_search_admin_form_submit(&$form, &$form_state) {
$table = $form['#table'];
$meta = $table
->get('meta');
if (isset($form_state['values']['fields'])) {
foreach ($form_state['values']['fields'] as $field_name => $settings) {
foreach ($settings as $setting => $value) {
$meta['fields'][$field_name][$setting] = $value;
}
}
}
$table
->update(array(
'meta' => $meta,
));
views_invalidate_cache();
}
function theme_data_search_admin_form($form) {
$rows = array();
foreach (element_children($form['fields']) as $e) {
$row = array();
foreach (element_children($form['fields'][$e]) as $f) {
$row[] = drupal_render($form['fields'][$e][$f]);
}
$rows[] = $row;
}
$header = array(
t('Name'),
t('Search index'),
);
$output = theme('table', $header, $rows);
$output .= drupal_render($form);
return $output;
}