You are here

function location_form in Location 5.3

Same name and namespace in other branches
  1. 5 location.inc \location_form()
  2. 6.3 location.module \location_form()
  3. 7.5 location.module \location_form()
  4. 7.3 location.module \location_form()
  5. 7.4 location.module \location_form()

Get form elements for editing locations on an object.

2 calls to location_form()
location_node_form_alter in ./location_node.module
Implementation of hook_form_alter().
location_user_user in ./location_user.module
Implementation of hook_user().

File

./location.module, line 1630
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']);
  $form = array(
    '#type' => 'fieldset',
    '#title' => format_plural($numforms, 'Location', 'Locations'),
    '#tree' => TRUE,
    '#attributes' => array(
      'class' => 'locations',
    ),
    '#weight' => $settings['form']['weight'],
    '#collapsible' => $settings['form']['collapsible'],
    '#collapsed' => $settings['form']['collapsed'],
  );

  // If there is only one form, hide the outer fieldset.
  if ($settings['multiple']['max'] == 1) {
    $form['#type'] = 'markup';
  }
  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',
      '#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');

    // If the user had configured the form for a single location, inherit
    // the collapsible / collapsed settings.
    $form[0]['#collapsible'] = $form['#collapsible'];
    $form[0]['#collapsed'] = $form['#collapsed'];
  }
  return $form;
}