You are here

function _phone_update_phone_instance_settings in Phone 7.2

Helper function for migrate/update functions: convert phone-6.x and phone-7.x-1.x instance settings to new values.

2 calls to _phone_update_phone_instance_settings()
phone_content_migrate_instance_alter in ./phone.content_migrate.inc
Implements hook_content_migrate_instance_alter().
phone_update_7200 in ./phone.install

File

./phone.module, line 1270
The phone module lets administrators use a phone number field type.

Code

function _phone_update_phone_instance_settings(&$data, $country_info) {

  // Get our new field info, in particular the default instance settings.
  $info = phone_field_info();
  $format_info = phone_field_formatter_info();

  // Initialize all missing/changed instance information.
  $data['widget_type'] = $info['phone']['default_widget'];
  $data['settings'] += $info['phone']['instance_settings'];
  $data['settings']['country_options']['default_country'] = $country_info['new'];
  if ($country_info['orig'] == 'int') {
    $data['settings']['country_options']['enable_default_country'] = FALSE;
    $data['settings']['country_options']['all_country_codes'] = TRUE;
  }
  else {
    $data['settings']['country_options']['enable_default_country'] = TRUE;
    $data['settings']['country_options']['all_country_codes'] = FALSE;
    $data['settings']['country_options']['country_codes']['hide_single_cc'] = TRUE;
    $data['settings']['country_options']['country_codes']['country_selection'] = array(
      $country_info['new'] => 1,
    );
  }

  // Update all display formatters to be as similar as possible to
  // previous formats.
  foreach ($data['display'] as $context => $ddata) {
    if (is_array($ddata)) {
      if ($country_info['orig'] == 'int') {
        $data['display'][$context]['type'] = 'phone_international';
      }
      else {
        $data['display'][$context]['type'] = 'phone_national';
      }
      $data['display'][$context]['settings'] = $format_info[$data[$context]['type']]['settings'];
    }
  }

  // Clear obsolete instance settings.
  unset($data['settings']['phone_country_code']);
  unset($data['settings']['phone_default_country_code']);
  unset($data['settings']['phone_int_max_length']);

  // @todo: Put formatting information into formatter.  But what values were people using?
  // Not all options can be transferred over, but should the options that correspond to
  // new settings be transferred (such as empty values for both)?
  unset($data['settings']['ca_phone_separator']);
  unset($data['settings']['ca_phone_parentheses']);
}