Index: text.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck/text.module,v
retrieving revision 1.32.2.13
diff -u -r1.32.2.13 text.module
--- text.module	5 Dec 2006 23:58:53 -0000	1.32.2.13
+++ text.module	14 Dec 2006 20:29:48 -0000
@@ -48,16 +48,29 @@
       );
       $form['allowed_values'] = array(
         '#type' => 'textarea',
-        '#title' => t('Allowed values'),
+        '#title' => t('Allowed values list'),
         '#default_value' => isset($field['allowed_values']) ? $field['allowed_values'] : '',
         '#required' => FALSE,
         '#rows' => 10,
-        '#description' => t('The possible values this field can contain. Any other values will result in an error. Enter one value per line.'),
+        '#description' => t('The possible values this field can contain. Enter one value per line, in the format key|label. The key is the value that will be stored in the database and it must match the field storage type, %type. The label is optional and the key will be used as the label if no label is specified.', array('%type' => $field['type'])),
+      );
+      $form['advanced_options'] = array(
+        '#type' => 'fieldset',
+        '#title' => t('Php code'),
+        '#collapsible' => TRUE,
+        '#collapsed' => TRUE,
+      );
+      $form['advanced_options']['allowed_values_php'] = array(
+        '#type' => 'textarea',
+        '#title' => t('Code'),
+        '#default_value' => $field['allowed_values_php'],
+        '#rows' => 6,
+        '#description' => t('Advanced Usage Only: PHP code that returns a keyed array of allowed values. Should not include &lt;?php ?&gt; delimiters. If this field is filled out, the array returned by this code will override the allowed values list above.'),
       );
       return $form;
 
     case 'save':
-      return array('text_processing', 'max_length', 'allowed_values');
+      return array('text_processing', 'max_length', 'allowed_values', 'allowed_values_php');
 
     case 'database columns':
       $columns = array(
@@ -76,19 +89,17 @@
       return $columns;
 
     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)) {
-        return array(
-          'default' => array(
-            'list' => drupal_map_assoc($allowed_values),
-            'list-type' => 'list',
-            'operator' => 'views_handler_operator_or',
-            'value-type' => 'array',
-          ),
-        );
-      }
+      $allowed_values = text_allowed_values($field);
+       if (count($allowed_values)) {
+         return array(
+           'default' => array(
+            'list' => $allowed_values,
+             'list-type' => 'list',
+             'operator' => 'views_handler_operator_or',
+             'value-type' => 'array',
+            ),
+          );
+        }
       else {
         return array(
           'like' => array(
@@ -113,15 +124,13 @@
       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');
+      $allowed_values = text_allowed_values($field);
 
       if (is_array($items)) {
         foreach ($items as $delta => $item) {
           $error_field = $field['field_name'].']['.$delta.'][value';
           if ($item['value'] != '') {
-            if (count($allowed_values) && !in_array($item['value'], $allowed_values)) {
+            if (count($allowed_values) && !array_key_exists($item['value'], $allowed_values)) {
               form_set_error($error_field, t('Illegal value for %name.', array('%name' => t($field['widget']['label']))));
             }
           }
@@ -161,6 +170,11 @@
   if (!isset($item['value'])) {
     return '';
   }
+  
+  if ($allowed_values = text_allowed_values($field)) {
+    return $allowed_values[$item['value']];
+  }
+  
   if ($field['text_processing']) {
     $text = check_markup($item['value'], $item['format'], is_null($node) || isset($node->in_preview));
   }
@@ -339,3 +353,30 @@
       break;
   }
 }
+
+/**
+ *  Create an array of the allowed values for this field
+ */
+function text_allowed_values($field) {
+  
+  $allowed_values = array();
+  if ($field['allowed_values_php']) {
+    ob_start();
+    $result = eval($field['allowed_values_php']);
+    if (is_array($result)) {
+      $allowed_values = $result;
+    }
+    ob_end_clean();
+  }
+  if (!$allowed_values) {
+    
+    $list = explode("\n", $field['allowed_values']);
+    $list = array_map('trim', $list);
+    $list = array_filter($list, 'strlen');
+    foreach ($list as $opt) {
+      list ($key, $value) = explode('|', $opt);
+      $allowed_values[$key] = $value ? $value : $key;
+    }
+  }
+  return $allowed_values;
+}
Index: number.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck/number.module,v
retrieving revision 1.27.2.10
diff -u -r1.27.2.10 number.module
--- number.module	22 Nov 2006 14:37:49 -0000	1.27.2.10
+++ number.module	14 Dec 2006 20:35:00 -0000
@@ -45,11 +45,24 @@
       );
       $form['allowed_values'] = array(
         '#type' => 'textarea',
-        '#title' => t('Allowed values'),
+        '#title' => t('Allowed values list'),
         '#default_value' => isset($field['allowed_values']) ? $field['allowed_values'] : '',
         '#required' => FALSE,
         '#rows' => 10,
-        '#description' => t('The possible values this field can contain. Any other values will result in an error. Enter one value per line.'),
+        '#description' => t('The possible values this field can contain. Enter one value per line, in the format key|label. The key is the value that will be stored in the database and it must match the field storage type, %type. The label is optional and the key will be used as the label if no label is specified.', array('%type' => $field['type'])),
+      );
+      $form['advanced_options'] = array(
+        '#type' => 'fieldset',
+        '#title' => t('Php code'),
+        '#collapsible' => TRUE,
+        '#collapsed' => TRUE,
+      );
+      $form['advanced_options']['allowed_values_php'] = array(
+        '#type' => 'textarea',
+        '#title' => t('Code'),
+        '#default_value' => $field['allowed_values_php'],
+        '#rows' => 6,
+        '#description' => t('Advanced Usage Only: PHP code that returns a keyed array of allowed values. Should not include &lt;?php ?&gt; delimiters. If this field is filled out, the array returned by this code will override the allowed values list above.'),
       );
       return $form;
 
@@ -63,7 +76,7 @@
       break;
 
     case 'save':
-      return array('min', 'max', 'allowed_values');
+      return array('min', 'max', 'allowed_values', 'allowed_values_php');
 
     case 'database columns':
       if ($field['type'] == 'number_integer') {
@@ -78,13 +91,11 @@
       }
 
     case 'filters':
-      $allowed_values = explode("\n", $field['allowed_values']);
-      $allowed_values = array_map('trim', $allowed_values);
-      $allowed_values = array_filter($allowed_values, 'strlen');
+      $allowed_values = number_allowed_values($field);
       if (count($allowed_values)) {
         return array(
           'default' => array(
-            'list' => drupal_map_assoc($allowed_values),
+            'list' => $allowed_values,
             'list-type' => 'list',
             'operator' => 'views_handler_operator_or',
             'value-type' => 'array',
@@ -114,9 +125,7 @@
       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');
+      $allowed_values = number_allowed_values($field);
 
       if (is_array($items)) {
         foreach ($items as $delta => $item) {
@@ -128,7 +137,7 @@
             if (is_numeric($field['max']) && $item['value'] > $field['max']) {
               form_set_error($error_field, 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($allowed_values) && !array_key_exists($item['value'], $allowed_values)) {
               form_set_error($error_field, t('Illegal value for %name.', array('%name' => t($field['widget']['label']))));
             }
           }
@@ -142,6 +151,11 @@
  * Implementation of hook_field_formatter_info().
  */
 function number_field_formatter_info() {
+  
+  if ($allowed_values = number_allowed_values($field)) {
+    return $allowed_values[$item['value']];
+  }
+
   return array(
     'default' => array(
       'label' => 'Default',
@@ -230,3 +244,30 @@
       break;
   }
 }
+
+/**
+ *  Create an array of the allowed values for this field
+ */
+function number_allowed_values($field) {
+  
+  $allowed_values = array();
+  if ($field['allowed_values_php']) {
+    ob_start();
+    $result = eval($field['allowed_values_php']);
+    if (is_array($result)) {
+      $allowed_values = $result;
+    }
+    ob_end_clean();
+  }
+  if (!$allowed_values) {
+    
+    $list = explode("\n", $field['allowed_values']);
+    $list = array_map('trim', $list);
+    $list = array_filter($list, 'strlen');
+    foreach ($list as $opt) {
+      list ($key, $value) = explode('|', $opt);
+      $allowed_values[$key] = $value ? $value : $key;
+    }
+  }
+  return $allowed_values;
+}
Index: optionwidgets.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck/optionwidgets.module,v
retrieving revision 1.8.2.2
diff -u -r1.8.2.2 optionwidgets.module
--- optionwidgets.module	17 Oct 2006 13:42:47 -0000	1.8.2.2
+++ optionwidgets.module	14 Dec 2006 20:22:33 -0000
@@ -20,14 +20,16 @@
  * Implementation of hook_widget_info().
  */
 function optionwidgets_widget_info() {
+  
+  $option_types = array('text', 'number_integer', 'number_decimal');
   return array(
     'options_select' => array(
       'label' => 'Select list',
-      'field types' => array('text', 'number_integer', 'number_decimal'),
+      'field types' => $option_types,
     ),
     'options_buttons' => array(
       'label' => 'Check boxes/radio buttons',
-      'field types' => array('text', 'number_integer', 'number_decimal'),
+      'field types' => $option_types,
     ),
   );
 }
@@ -39,24 +41,25 @@
   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_search($value, array_keys($options));
         if ($key) {
-          $keys[] = $key;
+          $keys[] = $value;
         }
       }
-
+      
       if ($field['multiple']) {
         $node_field['default keys'] = $keys;
       }
       else {
         $node_field['default key'] = reset($keys);
       }
+      
       break;
 
     case 'form':
@@ -65,7 +68,7 @@
       $form = array();
 
       $form[$field['field_name']] = array('#tree' => TRUE);
-
+      
       switch ($field['widget']['type']) {
         case 'options_select':
           if (!$field['required']) $options = array('' => '') + $options;
@@ -127,16 +130,16 @@
       else {
         $keys = array($node_field['key']);
       }
-
+      
       $values = array();
       foreach ($keys as $key) {
         if (isset($options[$key])) {
-          $values[] = $options[$key];
+          $values[] = $key;
         }
       }
-
+      
       $node_field = content_transpose_array_rows_cols(array('value' => $values));
-
+      
       // Remove the widget's data representation so it isn't saved.
       unset($node_field['keys']);
       unset($node_field['key']);
@@ -145,16 +148,14 @@
 }
 
 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++;
+  
+  $types = _content_field_types();
+  $field_allowed_values = $types[$field['type']]['module'] .'_allowed_values';
+  if (function_exists($field_allowed_values)) {
+    return $field_allowed_values($field);
   }
-  return (drupal_map_assoc($return_array));
+  else {
+    return array();
+  }
+
 }
\ No newline at end of file
