You are here

function phone_field_instance_settings_form in Phone 7.2

Same name and namespace in other branches
  1. 7 phone.module \phone_field_instance_settings_form()

Implements hook_field_instance_settings_form().

File

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

Code

function phone_field_instance_settings_form($field, $instance) {
  $defaults = field_info_instance_settings($field['type']);
  $settings = array_merge($defaults, $instance['settings']);
  $country_options = $settings['country_options'];
  $country_selection = array_filter($country_options['country_codes']['country_selection']);
  $countries = phone_countries();
  $module_path = drupal_get_path('module', 'phone');
  $form['country_options'] = array(
    '#title' => 'Country options',
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#weight' => -3,
    '#attached' => array(
      'css' => array(
        $module_path . '/theme/phone-settings.css',
      ),
      'js' => array(
        $module_path . '/theme/phone-settings.js',
      ),
    ),
  );
  $form['country_options']['enable_country'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable country dropdown'),
    '#default_value' => $country_options['enable_country'],
    '#description' => t('Uncheck this to disable the country dropdown. Users will still be able to input international numbers, provided they input them in international format. If input in national format, the number will be validated against the default country below. If no default country is selected, any national number will fail validation. Country selection will also enable a restriction on what calling codes can be used.'),
    '#weight' => -11,
  );
  $form['country_options']['enable_default_country'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable default country code'),
    '#default_value' => $country_options['enable_default_country'],
    '#description' => t('Check this to enable the default country code below.'),
    '#weight' => -10,
  );
  $form['country_options']['default_country'] = array(
    '#type' => 'select',
    '#title' => t('Default country code'),
    '#default_value' => $country_options['default_country'],
    '#options' => $countries,
    '#description' => t('This will be the default country selection.'),
    '#states' => array(
      'invisible' => array(
        ':input[name="instance[settings][country_options][enable_default_country]"]' => array(
          'checked' => FALSE,
        ),
      ),
    ),
    '#weight' => -9,
  );
  $form['country_options']['all_country_codes'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show all country codes.'),
    '#default_value' => $country_options['all_country_codes'],
    '#description' => t('Uncheck this to select the countries to be displayed.'),
    '#weight' => -8,
  );
  $form['country_options']['country_codes'] = array(
    '#title' => 'Country selection',
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#attributes' => array(
      'class' => array(
        'phone-settings',
      ),
    ),
    '#states' => array(
      'visible' => array(
        ':input[name="instance[settings][country_options][all_country_codes]"]' => array(
          'checked' => FALSE,
        ),
      ),
    ),
  );
  $form['country_options']['country_codes']['hide_single_cc'] = array(
    '#type' => 'checkbox',
    '#title' => t('Hide when only one country code'),
    '#default_value' => $country_options['country_codes']['hide_single_cc'],
    '#description' => t('By default when there is only one country code, it will show as a display-only form element. Check this to hide the country code.'),
    '#states' => array(
      'invisible' => array(
        ':input[name="instance[settings][country_options][enable_country]"]' => array(
          'checked' => FALSE,
        ),
      ),
    ),
  );
  $default = $country_options['enable_default_country'] ? drupal_map_assoc(array(
    $country_options['default_country'],
  )) : array();
  $form['country_options']['country_codes']['country_selection'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Select country codes to be included'),
    '#default_value' => isset($country_selection) && !empty($country_selection) ? $country_selection : $default,
    '#options' => $countries,
  );
  $form['enable_extension'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable phone extension support'),
    '#default_value' => $settings['enable_extension'],
    '#description' => t('Check this to enable the phone number extension field.'),
    '#weight' => -2.6,
  );
  return $form;
}