field_id;
// Get the parameters for creating the pulldown menu.
list($start, $step, $end) = explode(',', $field->options[1]);
list($prefix, $suffix) = explode(',', $field->options[2]);
// Work with the absolute value of the step. The traversal code will
// handle the direction.
$step = abs($step);
// Get the maximum number of decimal places for formatting purposes.
$decimals = max(strlen(substr(strrchr($start, '.'), 1)),
strlen(substr(strrchr($step, '.'), 1)),
strlen(substr(strrchr($end, '.'), 1)));
// Avoid infinite loops.
if (!$step) {
$step = 1;
}
// Set a non-option.
$options = array('' => '<'. t('none') .'>');
// Create each element in the list by stepping through all
// of the possible values.
if ($start <= $end) {
// The numbers are increasing.
for ($value = $start; $value <= $end; $value += $step) {
$valuestring = $prefix . number_format($value, $decimals) . $suffix;
$options[$valuestring] = $valuestring;
}
} else /* $start > $end */ {
// The numbers are decreasoing.
for ($value = $start; $value >= $end; $value -= $step) {
$valuestring = number_format($value, $decimals);
$options[$valuestring] = $valuestring;
}
}
// Remove the non-option if this is a required field.
if ($field->required) {
unset($options['']);
}
// Return the resulting form element.
return form_select(t($field->label), $fieldname, $node->$fieldname, $options,
t($field->description), 0, FALSE, $field->required);
}
function flexinode_field_numbersdropdown_db_select($field) {
$fieldname = 'flexinode_'. $field->field_id;
return $fieldname .'.textual_data AS '. $fieldname;
}
function flexinode_field_numbersdropdown_db_sort_column($field) {
return 'flexinode_'. $field->field_id .'.textual_data';
}
function flexinode_field_numbersdropdown_insert($field, $node) {
$fieldname = 'flexinode_'. $field->field_id;
db_query("INSERT INTO {flexinode_data} (nid, field_id, textual_data) VALUES (%d, %d, '%s')", $node->nid, $field->field_id, $node->$fieldname);
}
function flexinode_field_numbersdropdown_format($field, $node, $brief = 0) {
$fieldname = 'flexinode_'. $field->field_id;
return check_plain($node->$fieldname);
}
function flexinode_field_numbersdropdown_validate($field, $node) {
$fieldname = 'flexinode_'. $field->field_id;
return array('value' => $node->$fieldname);
}
function flexinode_field_numbersdropdown_config($field, $edit) {
// Set some useful defaults.
if (!isset($edit['options'])) {
$edit['options'][1] = '1,1,10';
$edit['options'][2] = ',';
}
// Create the form box with the extra options included.
$fields = form_textfield(t('Starting number, Step, Ending Number
' .
'(e.g. "2,2,10" => options 2, 4, 6, 8, and 10)'),
'options][', $edit['options'][1], 10, 20);
$fields .= form_textfield(t('Prefix, Suffix
' .
'(e.g. "$,/hour" => $50/hour)'),
'options][', $edit['options'][2], 10, 20);
return form_group(t('Options'), $fields,
t('These are the options for your numbers dropdown field.'));
}
/**
* @addtogroup themeable
* @{
*/
/**
* Format a single-line text field for display in a node.
*
* @param field_id
* Which field is being displayed (useful when overriding this function
* if you want to style one particular field differently).
* @param label
* The label for the field as displayed on the node form.
* @param value
* The value that the user entered for the field.
* @param formatted_value
* The value that the user entered for the field as pre-formatted by the module.
*/
function theme_flexinode_numbersdropdown($field_id, $label, $value, $formatted_value) {
$output = theme('form_element', $label, $formatted_value);
$output = '