You are here

function cck_phone_field_instance_settings_form in Phone Number 7

Implements hook_field_instance_settings_form().

File

./cck_phone.module, line 133
Defines phone number fields for CCK. Provide some verifications on the phone numbers

Code

function cck_phone_field_instance_settings_form($field, $instance) {
  drupal_add_css(drupal_get_path('module', 'cck_phone') . '/cck_phone.css');
  drupal_add_js(drupal_get_path('module', 'cck_phone') . '/cck_phone.js');
  $defaults = field_info_instance_settings($field['type']);
  $settings = array_merge($defaults, $instance['settings']);
  $form = array();
  $form['enable_default_country'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable default country code'),
    '#default_value' => $settings['enable_default_country'],
    '#description' => t('Check this to enable default country code below.'),
  );
  $form['default_country'] = array(
    '#type' => 'select',
    '#title' => t('Default country code'),
    '#default_value' => $settings['default_country'],
    '#options' => _cck_phone_cc_options(TRUE),
    '#description' => t('Item marked with * comes with country level phone number validation.'),
    '#states' => array(
      'invisible' => array(
        ':input[name="instance[settings][enable_default_country]"]' => array(
          'checked' => FALSE,
        ),
      ),
    ),
  );
  $form['all_country_codes'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show all country codes.'),
    '#default_value' => $settings['all_country_codes'],
    '#description' => t('Uncheck this to select the country to be displayed.'),
  );

  // Country codes settings
  $form['country_codes'] = array(
    '#title' => 'Country selection',
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#attributes' => array(
      'class' => array(
        'cck-phone-settings',
      ),
    ),
    '#states' => array(
      'visible' => array(
        ':input[name="instance[settings][all_country_codes]"]' => array(
          'checked' => FALSE,
        ),
      ),
    ),
  );
  $form['country_codes']['hide_single_cc'] = array(
    '#type' => 'checkbox',
    '#title' => t('Hide when only one country code'),
    '#default_value' => $settings['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.'),
  );
  $form['country_codes']['country_selection'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Select country codes to be included'),
    '#default_value' => isset($settings['country_codes']['country_selection']) && !empty($settings['country_codes']['country_selection']) ? $settings['country_codes']['country_selection'] : array(
      $settings['default_country'] => $settings['default_country'],
    ),
    '#options' => _cck_phone_cc_options(TRUE),
    '#description' => t('Country marks with <em>*</em> has custom country code settings and/or validation.'),
  );
  if (isset($settings['country_codes']['country_selection']) && !empty($settings['country_codes']['country_selection'])) {
    $form['country_codes']['country_selection']['#default_value'] = $settings['country_codes']['country_selection'];
  }
  elseif ($settings['enable_default_country']) {
    $form['country_codes']['country_selection']['#default_value'] = array(
      $settings['default_country'] => $settings['default_country'],
    );
  }
  $form['country_code_position'] = array(
    '#type' => 'radios',
    '#title' => t('Country code position'),
    '#options' => array(
      'before' => t('Before phone number'),
      'after' => t('After phone number'),
    ),
    '#default_value' => $settings['country_code_position'],
    '#description' => t('Select the position of the country code selection field relative to the phone number text field.'),
  );
  $form['enable_country_level_validation'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable country level validation'),
    '#default_value' => $settings['enable_country_level_validation'],
    '#description' => t('Uncheck this to disable stringent country phone number validation.'),
  );
  $form['enable_extension'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable phone extension support'),
    '#default_value' => $settings['enable_extension'],
    '#description' => t('Check this to enable phone number extension field.'),
  );

  // Display country specific settings
  foreach (_cck_phone_custom_cc() as $cc) {
    $function = $cc . '_phone_field_settings';
    if (function_exists($function)) {
      $country_settings = $function($op, $field);
      if (isset($country_settings) && !empty($country_settings)) {
        $country_codes = cck_phone_countrycodes($cc);

        // Wrap with fieldset
        $wrapper = array(
          '#title' => t('%country specific settings', array(
            '%country' => $country_codes['country'],
          )),
          '#type' => 'fieldset',
          '#collapsible' => TRUE,
          '#collapsed' => TRUE,
          '#attributes' => array(
            'class' => 'cck-phone-settings cck-phone-settings-' . $cc,
          ),
        );
        $wrapper[] = $country_settings;
        array_push($form, $wrapper);
      }
    }
  }
  return $form;
}