function location_phone_form_alter in Location 5
File
- contrib/location_phone/location_phone.module, line 3
Code
function location_phone_form_alter($form_id, &$form) {
if ($form_id == 'node_type_form') {
$type = $form['#node_type']->type;
$form['location']['location_phone'] = array(
'#type' => 'radios',
'#title' => 'Phone numbers',
'#default_value' => variable_get('location_phone_' . $type, 0),
'#options' => array(
t('Do not collect phone numbers for content of this type.'),
t('Allow phone numbers to be submitted for content of this type.'),
t('Require phone numbers to be submitted for content of this type.'),
),
'#prefix' => '<div style="margin-left: 40px">',
'#suffix' => '</div>',
'#weight' => 9,
);
}
elseif (isset($form['type']) && $form['type']['#value'] . '_node_form' == $form_id && variable_get('location_maxnum_' . $form['type']['#value'], 0) && variable_get('location_phone_' . $form['type']['#value'], 0)) {
$type = $form['type']['#value'];
$node = $form['#node'];
$location_form_count = $node->nid ? max(count($node->locations), variable_get('location_defaultnum_' . $node->type, 1)) : variable_get('location_defaultnum_' . $node->type, 1);
for ($index = 0; $index < $location_form_count; $index++) {
$form['locations'][$index]['phone'] = array_merge(is_array($form['locations'][$index]['phone']) ? $form['locations'][$index]['phone'] : array(), array(
'#type' => 'textfield',
'#title' => t('Phone number'),
'#default_value' => isset($node->locations[$index]['phone']) ? $node->locations[$index]['phone'] : '',
'#size' => 31,
'#maxlength' => 31,
'#required' => $index == 0 && variable_get('location_phone_' . $type, 0) == 2,
'#weight' => 8,
));
}
}
elseif ($form_id == 'location_extra') {
$arg0 = arg(0);
$arg1 = arg(1);
$arg2 = arg(2);
if ($arg0 == 'node' && is_numeric($arg1) && empty($arg2)) {
$node = node_load($arg1);
if (variable_get('location_phone_' . $node->type, 0)) {
$form['location']['phone'] = array_merge(is_array($form['location']['phone']) ? $form['location']['phone'] : array(), array(
'#type' => 'textfield',
'#title' => t('Phone number'),
'#size' => 31,
'#maxlength' => 31,
'#required' => count($node->locations) == 0 && variable_get('location_phone_' . $type, 0) == 2,
'#weight' => 8,
));
}
}
}
}