Index: modules/cck/content.module =================================================================== RCS file: /cvs/drupal/contributions/modules/cck/content.module,v retrieving revision 1.56.2.22 diff -U3 -r1.56.2.22 content.module --- modules/cck/content.module 20 Oct 2006 11:49:09 -0000 1.56.2.22 +++ modules/cck/content.module 27 Oct 2006 14:46:26 -0000 @@ -712,6 +712,9 @@ $field_result = db_query('SELECT * FROM {node_field} nf'); while ($field = db_fetch_array($field_result)) { $global_settings = $field['global_settings'] ? unserialize($field['global_settings']) : array(); + // create array from $global_settings['allowed_values'] + $global_settings['allowed_array'] = isset($global_settings['allowed_values']) ? _allowed2array ($global_settings['allowed_values']) : array(); + // error_log("1: " . print_r($global_settings['allowed_array'], true)); unset($field['global_settings']); $field = array_merge($field, $global_settings); $instance_info = db_fetch_array(db_query("SELECT type_name, label FROM {node_field_instance} WHERE field_name = '%s'", $field['field_name'])); @@ -753,6 +756,27 @@ return $info; } +function _allowed2array($allowedstring) { + $allowed_values = explode("\n", $allowedstring); + $allowed_values = array_map('trim', $allowed_values); + $allowed_values = array_filter($allowed_values, 'strlen'); + + // Create an array indexed starting at 1; checkboxes cannot have 0 keys. + $return_array = array(); + foreach ($allowed_values as $value) { + $line_values = explode("#", $value, 2); + $line_values = array_map('trim', $line_values); + $line_values = array_filter($line_values, 'strlen'); + if (count($line_values) > 1) { + $return_array[$line_values[0]] = $line_values[1]; + } else { + $return_array[$value] = $value; + } + } + return ($return_array); +// return (drupal_map_assoc($return_array)); +} + /** * Clear the cache of content_types; called in several places when content * information is changed. Index: modules/cck/number.module =================================================================== RCS file: /cvs/drupal/contributions/modules/cck/number.module,v retrieving revision 1.27.2.8 diff -U3 -r1.27.2.8 number.module --- modules/cck/number.module 21 Aug 2006 03:06:45 -0000 1.27.2.8 +++ modules/cck/number.module 27 Oct 2006 14:46:26 -0000 @@ -77,14 +77,14 @@ ); } - case 'filters': - $allowed_values = explode("\n", $field['allowed_values']); - $allowed_values = array_map('trim', $allowed_values); - $allowed_values = array_filter($allowed_values, 'strlen'); - if (count($allowed_values)) { + case 'filters': // *** TODO make filter-definitions views-compatible, they need to access $field['allowed_values'] +// $allowed_values = explode("\n", $field['allowed_values']); +// $allowed_values = array_map('trim', $allowed_values); +// $allowed_values = array_filter($allowed_values, 'strlen'); + if (count($field['allowed_array'])) { return array( 'default' => array( - 'list' => drupal_map_assoc($allowed_values), + 'list' => $field['allowed_array'], 'list-type' => 'list', 'operator' => 'views_handler_operator_or', 'value-type' => 'array', @@ -114,10 +114,6 @@ return theme('field', $node, $field, $items, $teaser, $page); case 'validate': - $allowed_values = explode("\n", $field['allowed_values']); - $allowed_values = array_map('trim', $allowed_values); - $allowed_values = array_filter($allowed_values, 'strlen'); - if (is_array($items)) { foreach ($items as $delta => $item) { if ($item['value'] != '') { @@ -127,7 +123,7 @@ if (is_numeric($field['max']) && $item['value'] > $field['max']) { form_set_error($field['field_name'], t('The value of %name may be no larger than %max.', array('%name' => t($field['widget']['label']), '%max' => $field['max']))); } - if (count($allowed_values) && !in_array($item['value'], $allowed_values)) { + if (count($field['allowed_array']) && !array_key_exists($item['value'], $field['allowed_array'])) { form_set_error($field['field_name'], t('Illegal value for %name.', array('%name' => t($field['widget']['label'])))); } } @@ -152,8 +148,13 @@ /** * Implementation of hook_field_formatter(). */ +// here we should make sure that the text is output instead of the number function number_field_formatter($field, $item, $formatter, $node) { - return check_plain($item['value']); + if (isset($field['allowed_array']) && count($field['allowed_array'])) { + return check_plain($field['allowed_array'][$item['value']]); + } else { + return check_plain($item['value']); + } } Index: modules/cck/optionwidgets.module =================================================================== RCS file: /cvs/drupal/contributions/modules/cck/optionwidgets.module,v retrieving revision 1.8.2.2 diff -U3 -r1.8.2.2 optionwidgets.module --- modules/cck/optionwidgets.module 17 Oct 2006 13:42:47 -0000 1.8.2.2 +++ modules/cck/optionwidgets.module 27 Oct 2006 14:46:26 -0000 @@ -38,16 +38,14 @@ function optionwidgets_widget($op, &$node, $field, &$node_field) { switch ($op) { case 'prepare form values': - $options = _optionwidgets_options($field); - $node_field_transposed = content_transpose_array_rows_cols($node_field); $values = (isset($node_field_transposed['value']) && is_array($node_field_transposed['value'])) ? $node_field_transposed['value'] : array(); $keys = array(); foreach ($values as $value) { - $key = array_search($value, $options); + $key = array_key_exists($value, $field['allowed_array']); if ($key) { - $keys[] = $key; + $keys[] = $value; } } @@ -60,22 +58,21 @@ break; case 'form': - $options = _optionwidgets_options($field); - + $form = array(); $form[$field['field_name']] = array('#tree' => TRUE); switch ($field['widget']['type']) { case 'options_select': - if (!$field['required']) $options = array('' => '') + $options; + if (!$field['required']) $field['allowed_array'] = array('' => '') + $field['allowed_array']; if ($field['multiple']) { $form[$field['field_name']]['keys'] = array( '#type' => 'select', '#title' => t($field['widget']['label']), '#default_value' => $node_field['default keys'], '#multiple' => TRUE, - '#options' => $options, + '#options' => $field['allowed_array'], '#required' => $field['required'], '#description' => $field['widget']['description'], ); @@ -86,7 +83,7 @@ '#title' => t($field['widget']['label']), '#default_value' => $node_field['default key'], '#multiple' => FALSE, - '#options' => $options, + '#options' => $field['allowed_array'], '#required' => $field['required'], '#description' => $field['widget']['description'], ); @@ -99,7 +96,7 @@ '#type' => 'checkboxes', '#title' => t($field['widget']['label']), '#default_value' => $node_field['default keys'], - '#options' => $options, + '#options' => $field['allowed_array'], '#required' => $field['required'], '#description' => $field['widget']['description'], ); @@ -109,7 +106,7 @@ '#type' => 'radios', '#title' => t($field['widget']['label']), '#default_value' => $node_field['default key'], - '#options' => $options, + '#options' => $field['allowed_array'], '#required' => $field['required'], '#description' => $field['widget']['description'], ); @@ -119,7 +116,6 @@ return $form; case 'process form values': - $options = _optionwidgets_options($field); if ($field['multiple']) { $keys = $node_field['keys']; @@ -130,11 +126,10 @@ $values = array(); foreach ($keys as $key) { - if (isset($options[$key])) { - $values[] = $options[$key]; + if (isset($field['allowed_array'][$key])) { + $values[] = $key; // $options[$key]; // } } - $node_field = content_transpose_array_rows_cols(array('value' => $values)); // Remove the widget's data representation so it isn't saved. @@ -143,18 +138,3 @@ break; } } - -function _optionwidgets_options($field) { - $allowed_values = explode("\n", $field['allowed_values']); - $allowed_values = array_map('trim', $allowed_values); - $allowed_values = array_filter($allowed_values, 'strlen'); - - // Create an array indexed starting at 1; checkboxes cannot have 0 keys. - $return_array = array(); - $i = 1; - foreach ($allowed_values as $value) { - $return_array[$i] = $value; - $i++; - } - return (drupal_map_assoc($return_array)); -} \ No newline at end of file