geo/modules/geo_data/geo_data.module, line 69
- Versions
- 6
geo_data_field_settings($op, $field)
Implementation of hook_field_settings().
Code
<?php
function geo_data_field_settings($op, $field) {
$field_name = $field['field_name'];
switch ($op) {
case 'form':
$form = array();
$geo_tables = geo('tables', '/^content_field/');
$options = array();
foreach ($geo_tables as $table => $geo_field) $options[$table] = $table;
$form['geo_data_table'] = array(
'#type' => 'select',
'#title' => t('Table name'),
'#multiple' => FALSE,
'#options' => $options,
'#default_value' => $field['geo_data_table'],
'#required' => TRUE,
);
if ($table = $field['geo_data_table']) {
$columns = array();
foreach (geo('table_desc', $table) as $col => $desc) {
if (in_array($desc['type'], array_keys(geo('supported_types')))) {
$geo_type = $desc['type'];
}
$columns[$col] = $desc['description'] ? $desc['description'] : $col;
}
$form['geo_data_key'] = array(
'#type' => 'select',
'#multiple' => FALSE,
'#title' => t('Key column'),
'#options' => $columns,
'#default_value' => $field['geo_data_key'],
'#required' => TRUE,
);
$form['geo_data_value'] = array(
'#type' => 'select',
'#multiple' => TRUE,
'#title' => t('Value column'),
'#options' => $columns,
'#default_value' => $field['geo_data_value'],
'#required' => TRUE,
);
$form['geo_data_fields'] = array(
'#type' => 'select',
'#multiple' => TRUE,
'#title' => t('Additional fields'),
'#options' => $columns,
'#default_value' => $field['geo_data_fields'],
'#required' => FALSE,
);
// TODO Store the geometry type for this field, based on table type.
$form['geo_type'] = array('#type' => 'value', '#value' => $geo_type);
}
return $form;
case 'save':
return array('geo_data_table', 'geo_data_key', 'geo_data_value', 'geo_data_fields', 'geo_type');
case 'database columns':
return array(
'value' => array(
'type' => 'varchar',
'length' => 255,
'description' => t('Key to geospatial table values'),
),
);
case 'views data':
$data = content_views_field_views_data($field);
$table_alias = content_views_tablename($field);
$db_info = content_database_info($field);
$geo_alias = $table_alias .'_geo';
$key = $field['field_name'] .'_value';
// Add the referenced table to the joins.
$data[$geo_alias]['table'] = array(
'group' => t('Geospatial Data'),
'base' => array(
'field' => $field['geo_data_key'],
),
'join' => array(
'node' => array(
'table' => $field['geo_data_table'],
'field' => $field['geo_data_key'],
'left_table' => $table_alias,
'left_field' => $key,
),
),
);
// Switch the field handler to geo_data.
$data[$table_alias][$key]['field']['field'] = 'geo';
$data[$table_alias][$key]['field']['geo_table'] = $geo_alias;
$data[$table_alias][$key]['field']['handler'] = 'views_handler_field_geo_data';
// Switch the filter handler to geo
$data[$table_alias][$key]['filter']['handler'] = 'views_handler_filter_geo';
$data[$table_alias][$key]['filter']['geo_type'] = $field['geo_type'];
$data[$table_alias][$key]['filter']['geo_table'] = $geo_alias;
return $data;
}
}
?> 