You are here

function location_normalize_settings in Location 6.3

Same name and namespace in other branches
  1. 5.3 location.module \location_normalize_settings()
  2. 7.5 location.module \location_normalize_settings()
  3. 7.3 location.module \location_normalize_settings()
  4. 7.4 location.module \location_normalize_settings()

Adjust a settings array. This will add any missing pieces and will set up requirements.

2 calls to location_normalize_settings()
location_save in ./location.module
Save a location.
_location_expand_location in ./location.module
Process a location element.

File

./location.module, line 1377
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_normalize_settings(&$settings, $required = TRUE) {
  if (!isset($settings['form'])) {
    $settings['form'] = array();
  }
  if (!isset($settings['form']['fields'])) {
    $settings['form']['fields'] = array();
  }

  // Merge defaults in.
  $dummy = array();
  $ds = location_invoke_locationapi($dummy, 'defaults');
  foreach ($ds as $k => $v) {
    if (!isset($settings['form']['fields'][$k])) {
      $settings['form']['fields'][$k] = array();
    }
    $settings['form']['fields'][$k] = array_merge($v, $settings['form']['fields'][$k]);
  }

  // Adjust collection settings if the entire location is "optional."
  if (!$required) {

    // Relax non-required settings.
    foreach ($settings['form']['fields'] as $k => $v) {
      if (isset($v['collect'])) {
        if ($v['collect'] == 2) {

          // Required -> Optional.
          $settings['form']['fields'][$k]['collect'] = 1;
        }
      }
    }
  }
}