function cck_phone_phone_number_process in Phone Number 7
Process an individual element.
1 string reference to 'cck_phone_phone_number_process'
- cck_phone_element_info in ./
cck_phone.module - Implements hook_element_info().
File
- ./
cck_phone.module, line 734 - Defines phone number fields for CCK. Provide some verifications on the phone numbers
Code
function cck_phone_phone_number_process($element, &$form_state, $form) {
$item = $element['#value'];
$field = field_widget_field($element, $form_state);
$instance = field_widget_instance($element, $form_state);
$settings = $instance['settings'];
$element['number'] = array(
'#type' => 'textfield',
'#maxlength' => $field['settings']['size'],
'#size' => $field['settings']['size'],
// '#title' => t('Number'),
'#required' => $element['#delta'] == 0 && $element['#required'] ? $element['#required'] : FALSE,
'#default_value' => isset($item['number']) ? $item['number'] : NULL,
'#attached' => array(
'css' => array(
drupal_get_path('module', 'cck_phone') . '/cck_phone.css',
),
),
'#weight' => 0,
'#attributes' => array(
'class' => array(
'phone-number',
),
),
);
// If only one country code, make it as hidden form item
$country_list = array_count_values($settings['country_codes']['country_selection']);
if ($country_list['0'] == count($settings['country_codes']['country_selection']) - 1) {
foreach (array_keys($country_list) as $k => $v) {
if ($v != '0') {
// only one value other than '0'
$cc = cck_phone_countrycodes($v);
$element['country_codes'] = array(
'#type' => 'hidden',
'#value' => $v,
);
if (!$settings['country_codes']['hide_single_cc']) {
$element['country_codes_markup'] = array(
'#type' => 'item',
'#markup' => $value = $cc['country'] . ' (' . $cc['code'] . ')',
'#weight' => $settings['country_code_position'] == 'after' ? 1 : -1,
'#attributes' => array(
'class' => array(
'country-code',
),
),
);
}
}
}
}
else {
$element['country_codes'] = array(
'#type' => 'select',
// '#title' => 'Country code',
'#options' => _cck_phone_cc_options(),
'#weight' => $settings['country_code_position'] == 'after' ? 1 : -1,
'#attributes' => array(
'class' => array(
'country-code',
),
),
);
}
if (!$element['#required']) {
$element['country_codes']['#empty_option'] = t('- Select -');
}
if (isset($item['country_codes'])) {
$element['country_codes']['#default_value'] = $item['country_codes'];
}
elseif ($settings['enable_default_country']) {
$element['country_codes']['#default_value'] = $settings['default_country'];
}
return $element;
}