diff --git modules/field/modules/list/list.module modules/field/modules/list/list.module index 4310ab4..c28e84f 100644 --- modules/field/modules/list/list.module +++ modules/field/modules/list/list.module @@ -26,7 +26,7 @@ function list_field_info() { return array( 'list' => array( 'label' => t('List'), - 'description' => t('This field stores numeric keys from key/value lists of allowed values where the key is a simple alias for the position of the value, i.e. 0|First option, 1|Second option, 2|Third option.'), + 'description' => t('This field stores keys from key/value lists of allowed integer numbers where the stored numeric key has significance and must be preserved, i.e. \'Lifetime in days\': 1|1 day, 7|1 week, 31|1 month.'), 'settings' => array('allowed_values' => '', 'allowed_values_function' => ''), 'default_widget' => 'options_select', 'default_formatter' => 'list_default', @@ -40,7 +40,7 @@ function list_field_info() { ), 'list_number' => array( 'label' => t('List (numeric)'), - 'description' => t('This field stores keys from key/value lists of allowed numbers where the stored numeric key has significance and must be preserved, i.e. \'Lifetime in days\': 1|1 day, 7|1 week, 31|1 month.'), + 'description' => t('This field stores keys from key/value lists of allowed decimal numbers where the stored numeric key has significance and must be preserved, i.e. \'Lifetime in days\': 1|1 day, 7|1 week, 31|1 month.'), 'settings' => array('allowed_values' => '', 'allowed_values_function' => ''), 'default_widget' => 'options_select', 'default_formatter' => 'list_default', @@ -203,7 +203,7 @@ function list_allowed_values($field) { } elseif (!empty($field['settings']['allowed_values'])) { $position_keys = $field['type'] == 'list'; - $values = list_extract_allowed_values($field['settings']['allowed_values'], $position_keys); + $values = list_extract_allowed_values($field['settings']['allowed_values']); } $allowed_values[$field['id']] = $values; @@ -223,13 +223,8 @@ function list_allowed_values($field) { * 'allowed_values' setting: * - Values are separated by a carriage return. * - Each value is in the format "value|label" or "value". - * @param $position_keys - * Boolean value indicating whether to generate keys based on the position of - * the value if a key is not manually specified, effectively generating - * integer-based keys. This should only be TRUE for fields that have a type of - * "list". Otherwise the value will be used as the key if not specified. */ -function list_extract_allowed_values($string_values, $position_keys = FALSE) { +function list_extract_allowed_values($string_values) { $values = array(); $list = explode("\n", $string_values); @@ -240,9 +235,7 @@ function list_extract_allowed_values($string_values, $position_keys = FALSE) { if (strpos($value, '|') !== FALSE) { list($key, $value) = explode('|', $value); } - // Otherwise see if we need to use the value as the key. The "list" type - // will automatically convert non-keyed lines to integers. - elseif (!$position_keys) { + else { $key = $value; } $values[$key] = (isset($value) && $value !== '') ? $value : $key; diff --git modules/field/modules/list/tests/list.test modules/field/modules/list/tests/list.test index 3a1472d..d2152b6 100644 --- modules/field/modules/list/tests/list.test +++ modules/field/modules/list/tests/list.test @@ -140,6 +140,9 @@ class ListFieldUITestCase extends FieldTestCase { $edit = array($element_name => "1.1|one\n"); $this->drupalPost($admin_path, $edit, t('Save settings')); $this->assertText("keys must be integers", t('Form validation failed.')); + $edit = array($element_name => "one\n"); + $this->drupalPost($admin_path, $edit, t('Save settings')); + $this->assertText("keys must be integers", t('Form validation failed.')); // Test 'List (number)' field type. $admin_path = $this->createListFieldAndEdit('list_number'); @@ -147,6 +150,9 @@ class ListFieldUITestCase extends FieldTestCase { $edit = array($element_name => "1|one\nB|two"); $this->drupalPost($admin_path, $edit, t('Save settings')); $this->assertText("each key must be a valid integer or decimal", t('Form validation failed.')); + $edit = array($element_name => "one"); + $this->drupalPost($admin_path, $edit, t('Save settings')); + $this->assertText("each key must be a valid integer or decimal", t('Form validation failed.')); // Test 'List (text)' field type. $admin_path = $this->createListFieldAndEdit('list_text');