You are here

function phone_field_formatter_settings_form in Phone 7.2

Implements hook_field_formatter_settings_form().

File

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

Code

function phone_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
  $display = $instance['display'][$view_mode];
  $settings = $display['settings'];
  $element = array();
  $component_options = array(
    'country' => t('Country name'),
  );
  if (!empty($field['settings']['enable_numbertype'])) {
    $component_options['numbertype'] = t('Number type');
  }
  if (!empty($instance['settings']['enable_extension'])) {
    $component_options['extension'] = t('Extension');
  }
  $element['components'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Components to output'),
    '#default_value' => array_filter($settings['components']),
    '#options' => $component_options,
    '#description' => t('The number type and/or extension components will only be output if they are enabled in the widget settings.'),
  );
  $element['full_hcard'] = array(
    '#type' => 'checkbox',
    '#title' => t('Full hCard 1.0 type support'),
    '#default_value' => $settings['full_hcard'],
    '#description' => check_plain(t('When checked, the number type item will be output as an <abbr> tag instead of a <span>, and will include a title attribute.')),
  );
  $element['as_tel_link'] = array(
    '#type' => 'checkbox',
    '#title' => t('As tel: link'),
    '#default_value' => $settings['as_tel_link'],
  );
  $element['allow_alpha'] = array(
    '#type' => 'checkbox',
    '#title' => t('Convert alpha characters to digits'),
    '#description' => t('Will convert any alpha characters to their numerical equivalent based on the keypad defined in ITU E.161.'),
    '#default_value' => $settings['allow_alpha'],
  );
  $element['country_name_position'] = array(
    '#title' => t('Country name position'),
    '#type' => 'radios',
    '#options' => array(
      'before' => t('Before phone number'),
      'after' => t('After phone number'),
    ),
    '#default_value' => $settings['country_name_position'],
    '#states' => array(
      'visible' => array(
        ':input[name="fields[' . $field['field_name'] . '][settings_edit_form][settings][components][country]"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  if (!empty($field['settings']['enable_numbertype'])) {
    $element['numbertype_position'] = array(
      '#title' => t('Phone number type position'),
      '#type' => 'radios',
      '#options' => array(
        'before' => t('Before country name and phone number'),
        'after' => t('After country name and phone number'),
      ),
      '#default_value' => $settings['numbertype_position'],
      '#states' => array(
        'visible' => array(
          ':input[name="fields[' . $field['field_name'] . '][settings_edit_form][settings][components][numbertype]"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
  }

  // Do not allow extension_prefix to be specified for RFC3966 format, because
  // it specifies that extension prefix must be ';ext='
  if (!empty($instance['settings']['enable_extension']) && $display['type'] != 'phone_rfc3966') {
    $element['extension_prefix'] = array(
      '#title' => t('Phone extension prefix'),
      '#description' => t('Text to display before the phone\'s extension.  Be sure to include any desired spaces'),
      '#type' => 'textfield',
      '#size' => 15,
      '#default_value' => check_plain($settings['extension_prefix']),
      '#states' => array(
        'visible' => array(
          ':input[name="fields[' . $field['field_name'] . '][settings_edit_form][settings][components][extension]"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
  }
  return $element;
}