node_field_range.module in Node Field 7.2
File
modules/node_field_range/node_field_range.module
View source
<?php
require_once 'includes/node_field_range.api.inc';
function node_field_range_node_field_settings_alter($node_field, &$form) {
if ($node_field['type'] != 'text') {
return;
}
$form['range'] = array(
'#type' => 'fieldset',
'#title' => t('Allowed values'),
'#title_display' => 'before',
);
$form['range']['min'] = array(
'#type' => 'textfield',
'#title' => t('Min value'),
'#title_display' => 'before',
'#default_value' => isset($node_field['settings']['range']['min']) ? $node_field['settings']['range']['min'] : NULL,
'#description' => t('Leave blank to use max value only.'),
);
$form['range']['max'] = array(
'#type' => 'textfield',
'#title' => t('Max value'),
'#title_display' => 'before',
'#default_value' => isset($node_field['settings']['range']['max']) ? $node_field['settings']['range']['max'] : NULL,
'#description' => t('Leave blank to use min value only.'),
);
}
function node_field_range_form_node_form_alter(&$form, &$form_state) {
if (empty($form['node_fields'])) {
return;
}
foreach (element_children($form['node_fields']) as $id) {
if (empty($form['node_fields'][$id]['#type'])) {
continue;
}
if ($form['node_fields'][$id]['#type'] == 'textfield') {
$form['node_fields'][$id]['#element_validate'] = array(
'node_field_range_validation',
);
$form['node_fields'][$id]['#field_id'] = $id;
}
elseif ($form['node_fields'][$id]['#type'] == 'fieldset') {
foreach (element_children($form['node_fields'][$id]) as $id_in_group) {
if (isset($form['node_fields'][$id][$id_in_group]['#type']) && $form['node_fields'][$id][$id_in_group]['#type'] == 'textfield') {
$form['node_fields'][$id][$id_in_group]['#element_validate'] = array(
'node_field_range_validation',
);
$form['node_fields'][$id][$id_in_group]['#field_id'] = $id_in_group;
}
}
}
}
}