function location_fax_form_alter in Location 5
File
- contrib/location_fax/location_fax.module, line 3
Code
function location_fax_form_alter($form_id, &$form) {
if ($form_id == 'node_type_form') {
$type = $form['#node_type']->type;
$form['location']['location_fax'] = array(
'#type' => 'radios',
'#title' => 'Fax numbers',
'#default_value' => variable_get('location_fax_' . $type, 0),
'#options' => array(
t('Do not collect fax numbers for content of this type.'),
t('Allow fax numbers to be submitted for content of this type.'),
t('Require fax 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_fax_' . $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]['fax'] = array_merge(is_array($form['locations'][$index]['fax']) ? $form['locations'][$index]['fax'] : array(), array(
'#type' => 'textfield',
'#title' => t('Fax number'),
'#default_value' => isset($node->locations[$index]['fax']) ? $node->locations[$index]['fax'] : '',
'#size' => 31,
'#maxlength' => 31,
'#required' => $index == 0 && variable_get('location_fax_' . $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_fax_' . $node->type, 0)) {
$form['location']['fax'] = array_merge(is_array($form['location']['fax']) ? $form['location']['fax'] : array(), array(
'#type' => 'textfield',
'#title' => t('Fax number'),
'#size' => 31,
'#maxlength' => 31,
'#required' => count($node->locations) == 0 && variable_get('location_fax_' . $type, 0) == 2,
'#weight' => 8,
));
}
}
}
}