function location_cck_field_widget_form in Location 7.4
Same name and namespace in other branches
- 7.5 contrib/location_cck/location_cck.module \location_cck_field_widget_form()
- 7.3 contrib/location_cck/location_cck.module \location_cck_field_widget_form()
Implement hook_field_widget_form().
File
- contrib/
location_cck/ location_cck.module, line 279 - Defines location field type.
Code
function location_cck_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
if ($field['type'] == 'location') {
$settings = $field['settings']['location_settings'];
// Load location data for existing locations.
if (isset($items[$delta]['lid']) && $items[$delta]['lid']) {
// Are we in a node preview?
// If we aren't, then we only have the lid, because that's all cck
// actually knows about internally. So, we have to pull in the location
// at this point.
if (empty($items[$delta]['cck_preview_in_progress'])) {
$location = location_load_location($items[$delta]['lid']);
}
else {
// Otherwise, the data was already populated and we're running
// off the form state.
$location = $items[$delta];
}
}
else {
if (isset($items[$delta]) && is_array($items[$delta]) && !empty($items[$delta])) {
// Initialize empty location.
$location = location_empty_location($settings);
foreach ($items[$delta] as $k => $v) {
$location[$k] = $v;
}
// We can't trust that CCK is giving us the right information.
// It can't tell us whether $items is defaults or multistep values.
// Location *needs* the defaults to match the initial field values,
// so we re-calculate the defaults here and stash them into the settings.
// @@@ There is still a bug here!
// If you go back and edit something, and you hadn't set a location the
// first time, CCK fails to set up the defaults properly!
// I'm just going to leave it like that for now, because I don't know how
// to work around it.
$temp = content_default_value($form, $form_state, $field, 0);
if (is_array($temp) && isset($temp[$delta]) && is_array($temp[$delta])) {
foreach ($temp[$delta] as $k => $v) {
$settings['form']['fields'][$k]['default'] = $v;
}
}
// unset($location['location_settings']);
// unset($location['locpick']);
}
else {
$location = location_empty_location($settings);
}
}
$element = array(
'#type' => 'location_element',
'#title' => t($instance['label']),
'#description' => t($instance['description']),
'#required' => $instance['required'],
'#location_settings' => $settings,
'#default_value' => $location,
);
// This is used to determine whether we are in a preview or not, because
// several pieces of code work differently when previewing.
$element['cck_preview_in_progress'] = array(
'#type' => 'value',
'#value' => TRUE,
);
return $element;
}
}