function location_form in Location 7.3
Same name and namespace in other branches
- 5.3 location.module \location_form()
- 5 location.inc \location_form()
- 6.3 location.module \location_form()
- 7.5 location.module \location_form()
- 7.4 location.module \location_form()
Get form elements for editing locations on an object.
4 calls to location_form()
- location_node_form_node_form_alter in ./
location_node.module - Implements hook_form_BASE_FORM_ID_alter().
- location_taxonomy_form_alter in contrib/
location_taxonomy/ location_taxonomy.module - Implements hook_form_alter().
- location_user_form_user_profile_form_alter in ./
location_user.module - Implements hook_form_FORM_ID_alter().
- location_user_form_user_register_form_alter in ./
location_user.module - Implements hook_form_FORM_ID_alter().
File
- ./
location.module, line 2150 - Location module main routines. An implementation of a universal API for location manipulation. Provides functions for postal_code proximity searching, deep-linking into online mapping services. Currently, some options are configured through an…
Code
function location_form($settings, $locations) {
if (!isset($settings['multiple']['max']) || $settings['multiple']['max'] == 0) {
// Location not enabled for this object type.
// Bail out early.
return array();
}
// Generate location fieldsets.
$numloc = count($locations);
// Show up to 'add' number of additional forms, in addition to the preexisting
// locations. (Less if we'll hit 'max' first.)
$numforms = min($numloc + $settings['multiple']['add'], $settings['multiple']['max']);
if ($settings['multiple']['max'] == 1 || $settings['multiple']['add'] == 1) {
$form = array(
'#prefix' => '<div class="location-wrapper">',
'#suffix' => '</div>',
'#tree' => TRUE,
'#weight' => $settings['form']['weight'],
);
}
else {
$form = array(
'#type' => 'fieldset',
'#title' => format_plural($numforms, 'Location', 'Locations'),
'#tree' => TRUE,
'#attributes' => array(
'class' => array(
'locations',
),
),
'#weight' => $settings['form']['weight'],
'#collapsible' => $settings['form']['collapsible'],
'#collapsed' => $settings['form']['collapsed'],
);
}
for ($i = 0; $i < $numforms; $i++) {
$required = FALSE;
// Check if this is a required location.
if ($i < $settings['multiple']['min']) {
$required = TRUE;
}
$form[$i] = array(
'#type' => 'location_element',
'#has_garbage_value' => TRUE,
'#value' => '',
'#title' => t('Location #%number', array(
'%number' => $i + 1,
)),
'#default_value' => isset($locations[$i]) ? $locations[$i] : NULL,
'#location_settings' => $settings,
'#required' => $required,
);
}
// Tidy up the form in the single location case.
if ($numforms == 1) {
$form[0]['#title'] = t('Location', array(), array(
'context' => 'geolocation',
));
// If the user had configured the form for a single location, inherit
// the collapsible / collapsed settings.
$form[0]['#collapsible'] = $settings['form']['collapsible'];
$form[0]['#collapsed'] = $settings['form']['collapsed'];
}
return $form;
}