Index: cck.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/cck/cck.module,v
retrieving revision 1.31
diff -u -r1.31 cck.module
--- cck.module	24 Apr 2010 20:27:30 -0000	1.31
+++ cck.module	17 Oct 2010 09:19:23 -0000
@@ -52,14 +52,14 @@
  * users to input a function or a PHP snippet
  * that will return the allowed values.
  */
-function cck_allowed_values_form(&$form, $form_state, $field) { 
+function cck_allowed_values_form(&$form, $form_state, $field) {
   $php_code = cck_field_get_setting('allowed_values_php', 'field', $field);
   $allowed_values_function = $form['field']['settings']['allowed_values_function']['#value'];
   if (!empty($php_code)) {
     $allowed_values_function = 'cck_allowed_values_php';
   }
-  
-  // Add a field where users can specify a function 
+
+  // Add a field where users can specify a function
   // to return the allowed values list.
   $form['field']['settings']['allowed_values_function'] = array(
     '#type' => 'textfield',
@@ -67,14 +67,14 @@
     '#default_value' => $allowed_values_function,
     '#description' => t('The name of a function that will return the allowed values list.'),
   );
-        
+
   // Add a field where users can specify some PHP
   // code that will return the allowed values list.
-  $function = $field['module'] . '_field_schema';
-  $schema = $function($field);
-  $columns = array_keys($schema['columns']);  
+  module_load_install($field['module']);
+  $schema = (array) module_invoke($field['module'], 'field_schema', $field);
+  $columns = array_keys($schema['columns']);
   $sample = t("return array(\n  0 => array(@columns),\n  // You'll usually want to stop here. Provide more values\n  // if you want your 'default value' to be multi-valued:\n  1 => array(@columns),\n  2 => ...\n);", array('@columns' => implode(', ', $columns)));
-            
+
   $form['field']['settings']['allowed_values_php'] = array(
     '#access' => user_access('Use PHP input for field settings (dangerous - grant with care)'),
     '#type' => 'textarea',
@@ -85,7 +85,7 @@
       '@link_devel' => 'http://www.drupal.org/project/devel',
     )),
   );
-    
+
 }
 
 /**
@@ -93,16 +93,16 @@
  * users to input a function or a PHP snippet
  * that will return the default values.
  */
-function cck_default_value_form(&$form, $form_state, $field) { 
+function cck_default_value_form(&$form, $form_state, $field) {
   $instance = field_info_instance($form['instance']['entity_type']['#value'], $field['field_name'], $form['instance']['bundle']['#value']);
   $langcode = $form['instance']['default_value_widget'][$field['field_name']]['#language'];
   $php_code = cck_field_get_setting('default_value_php', 'instance', $field, $instance, $langcode);
-  $default_value_function = $instance['default_value_function'];
+  $default_value_function = isset($instance['default_value_function']) ? $instance['default_value_function'] : '';
   if (!empty($php_code)) {
     $default_value_function = 'cck_default_value_php';
   }
-  
-  // Add a field where users can specify a function 
+
+  // Add a field where users can specify a function
   // to return the default value.
   $form['instance']['default_value_widget']['default_value_function'] = array(
     '#type' => 'textfield',
@@ -110,14 +110,14 @@
     '#default_value' => $default_value_function,
     '#description' => t('The name of a function that will return the default value.'),
   );
-        
+
   // Add a field where users can specify some PHP
   // code that will return the default value.
-  $function = $field['module'] . '_field_schema';
-  $schema = $function($field);
-  $columns = array_keys($schema['columns']);  
+  module_load_install($field['module']);
+  $schema = (array) module_invoke($field['module'], 'field_schema', $field);
+  $columns = array_keys($schema['columns']);
   $sample = t("return array(\n  0 => array(@columns),\n  // You'll usually want to stop here. Provide more values\n  // if you want your 'default value' to be multi-valued:\n  1 => array(@columns),\n  2 => ...\n);", array('@columns' => implode(', ', $columns)));
-            
+
   $form['instance']['default_value_widget']['default_value_php'] = array(
     '#access' => user_access('Use PHP input for field settings (dangerous - grant with care)'),
     '#type' => 'textarea',
@@ -128,14 +128,14 @@
       '@link_devel' => 'http://www.drupal.org/project/devel',
     )),
   );
-    
+
 }
 
 /**
  * Validation handler to store php allowed values.
  */
-function cck_allowed_values_validate(&$element, &$form_state) {
-  $field = $form_state['values']['field'];
+function cck_allowed_values_validate(&$form, &$form_state) {
+  $field = isset($form['#field']) ? $form['#field'] : field_info_field($form['field']['field_name']['#value']);
   $php_code = $form_state['values']['field']['settings']['allowed_values_php'];
   $allowed_values_function = $form_state['values']['field']['settings']['allowed_values_function'];
   if (!empty($php_code)) {
@@ -144,24 +144,28 @@
   elseif (empty($php_code) && $allowed_values_function == 'cck_allowed_values_php') {
     $allowed_values_function = '';
   }
-  form_set_value($element['field']['settings']['allowed_values_function'], $allowed_values_function, $form_state);
+  form_set_value($form['field']['settings']['allowed_values_function'], $allowed_values_function, $form_state);
   cck_field_set_setting('allowed_values_php', 'field', $php_code, $field);
 }
 
 /**
  * Validation handler to store php default values.
  */
-function cck_default_value_validate(&$element, &$form_state) {
-  $field = $form_state['values']['field'];
-  $php_code = $form_state['values']['instance']['default_value_widget']['default_value_php'];
-  $default_value_function = $form_state['values']['instance']['default_value_function'];
+function cck_default_value_validate(&$form, &$form_state) {
+  $field = $form['#field'];
+  $instance = field_info_instance($form['instance']['entity_type']['#value'], $field['field_name'], $form['instance']['bundle']['#value']);
+  $langcode = $form['instance']['default_value_widget'][$field['field_name']]['#language'];
+
+  $php_code = $form_state['values']['default_value_php'];
+  $default_value_function = $form_state['values']['default_value_function'];
   if (!empty($php_code)) {
     $default_value_function = 'cck_default_value_php';
   }
   elseif (empty($php_code) && $default_value_function == 'cck_default_value_php') {
     $default_value_function = '';
   }
-  form_set_value($element['instance']['default_value_widget']['default_value_function'], $default_value_function, $form_state);
+
+  form_set_value($form['instance']['default_value_widget']['default_value_function'], $default_value_function, $form_state);
   cck_field_set_setting('default_value_php', 'instance', $php_code, $field, $instance, $langcode);
 }
 
@@ -230,6 +234,7 @@
  */
 function cck_field_set_setting($setting, $setting_type, $value, $field, $instance = NULL, $langcode = LANGUAGE_NONE) {
   // Delete any prior values.
+
   $bundle = ($setting_type == 'field' || empty($instance)) ? NULL : $instance['bundle'];
   $entity_type = ($setting_type == 'field' || empty($instance)) ? NULL : $instance['entity_type'];
   if ($setting_type == 'field' || empty($instance)) {
@@ -281,7 +286,7 @@
     $allowed_values = $result;
   }
   ob_end_clean();
-  return $allowed_values;  
+  return $allowed_values;
 }
 
 /**
@@ -327,12 +332,12 @@
 
 /**
  * Implements hook_content_migrate_field_alter().
- * 
+ *
  * Use this to tweak the conversion of field settings
  * from the D6 style to the D7 style for specific
  * situations not handled by basic conversion,
  * as when field types or settings are changed.
- * 
+ *
  * $field_value['widget_type'] is available to
  * see what widget type was originally used.
  */
@@ -345,7 +350,7 @@
 
 /**
  * Implements hook_content_migrate_instance_alter().
- * 
+ *
  * Use this to tweak the conversion of instance or widget settings
  * from the D6 style to the D7 style for specific
  * situations not handled by basic conversion, as when
