You are here

function location_form in Location 7.5

Same name and namespace in other branches
  1. 5.3 location.module \location_form()
  2. 5 location.inc \location_form()
  3. 6.3 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.

1 call to location_form()
location_taxonomy_form_alter in contrib/location_taxonomy/location_taxonomy.module
Implements hook_form_alter().

File

./location.module, line 1826
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' => 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');

    // 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;
}