function phone_element_process in Phone 7.2
Process an individual phone element.
1 string reference to 'phone_element_process'
- _phone_element_info in includes/
phone.element.inc - Implements hook_element_info().
File
- includes/
phone.element.inc, line 66 - Provides FAPI implementation for a phone element.
Code
function phone_element_process($element, &$form_state, $form) {
$item = $element['#value'];
$settings = $element['#phone_settings'];
$labels = array(
'type' => theme('phone_part_label_type', array(
'element' => $element,
)),
'number' => theme('phone_part_label_number', array(
'element' => $element,
)),
'extension' => theme('phone_part_label_extension', array(
'element' => $element,
)),
'country' => theme('phone_part_label_country', array(
'element' => $element,
)),
);
if ($settings['label_position'] == 'before') {
if (!isset($element['#attributes']['class'])) {
$element['#attributes']['class'] = array();
}
$element['#attributes']['class'][] = 'phone-label-before';
}
if ($settings['enable_numbertype'] && !empty($settings['numbertype_allowed_values'])) {
$element['numbertype'] = array(
'#type' => 'select',
'#title' => $labels['type'],
'#title_display' => $settings['label_position'] == 'none' ? 'invisible' : 'before',
'#options' => $settings['numbertype_allowed_values'],
'#weight' => $settings['numbertype_allowed_values_position'] == 'after' ? 5 : -5,
'#empty_option' => t('- Select -'),
'#default_value' => isset($item['numbertype']) ? $item['numbertype'] : NULL,
);
}
else {
$element['numbertype'] = array(
'#type' => 'hidden',
'#value' => isset($item['numbertype']) ? $item['numbertype'] : NULL,
);
}
$element['number'] = array(
'#type' => !empty($settings['use_tel_input']) ? 'phone_tel' : 'textfield',
'#title' => $labels['number'],
'#title_display' => $settings['label_position'] == 'none' ? 'invisible' : 'before',
'#maxlength' => $settings['number_size'],
'#size' => $settings['number_size'],
'#required' => $element['#delta'] == 0 && $element['#required'] ? $element['#required'] : FALSE,
'#default_value' => isset($item['number']) ? $item['number'] : NULL,
'#weight' => 0,
);
// If only one country code, make it as a hidden form item.
$country_options = $settings['country_options'];
$country_selection = array_filter($country_options['country_codes']['country_selection']);
if (!$country_options['all_country_codes'] && count($country_selection) == 1 || empty($country_options['enable_country'])) {
$countrycode = '';
if (!empty($country_options['enable_country'])) {
$countrycode = reset($country_selection);
}
elseif (!empty($country_options['enable_default_country'])) {
$countrycode = $country_options['default_country'];
}
$country = phone_countries($countrycode);
$element['countrycode'] = array(
'#type' => 'hidden',
'#value' => $countrycode,
);
if (!$country_options['country_codes']['hide_single_cc'] && !empty($country_options['enable_country'])) {
$element['country_code_markup'] = array(
'#type' => 'item',
'#title' => $labels['country'],
'#title_display' => $settings['label_position'] == 'none' ? 'invisible' : 'before',
'#markup' => $country,
'#weight' => $settings['country_code_position'] == 'after' ? 1 : -1,
);
}
}
else {
$element['countrycode'] = array(
'#type' => 'select',
'#title' => $labels['country'],
'#title_display' => $settings['label_position'] == 'none' ? 'invisible' : 'before',
'#options' => phone_countries($country_options['all_country_codes'] ? NULL : $country_selection),
'#weight' => $settings['country_code_position'] == 'after' ? 1 : -1,
'#empty_option' => t('- Guess from number -'),
);
if (isset($item['countrycode'])) {
$element['countrycode']['#default_value'] = $item['countrycode'];
}
elseif ($country_options['enable_default_country']) {
$element['countrycode']['#default_value'] = $country_options['default_country'];
}
}
if ($settings['enable_extension']) {
$element['extension'] = array(
'#type' => 'textfield',
'#title' => $labels['extension'],
'#title_display' => $settings['label_position'] == 'none' ? 'invisible' : 'before',
'#maxlength' => $settings['extension_size'],
'#size' => $settings['extension_size'],
'#title' => t('ext'),
'#required' => FALSE,
'#default_value' => isset($item['extension']) ? $item['extension'] : NULL,
'#weight' => 2,
);
}
else {
$element['extension'] = array(
'#type' => 'hidden',
'#value' => isset($item['extension']) ? $item['extension'] : NULL,
);
}
return $element;
}