5 * Install, update and uninstall functions for the list module.
9 * Implements hook_field_schema().
11 function list_field_schema($field) {
12 switch ($field['type']) {
41 'columns' => $columns,
43 'value' => array('value'),
49 * Rename the list field types and change 'allowed_values' format.
51 function list_update_7001() {
52 $fields = _update_7000_field_read_fields(array('module' => 'list'));
53 foreach ($fields as $field) {
56 // Translate the old string format into the new array format.
57 $allowed_values = $field['settings']['allowed_values'];
58 if (is_string($allowed_values)) {
59 $position_keys = ($field['type'] == 'list');
60 $allowed_values = _list_update_7001_extract_allowed_values($allowed_values, $position_keys);
62 // Additionally, float keys need to be disambiguated ('.5' is '0.5').
63 if ($field['type'] == 'list_number' && !empty($allowed_values)) {
64 $keys = array_map(create_function('$a', 'return (string) (float) $a;'), array_keys($allowed_values));
65 $allowed_values = array_combine($keys, array_values($allowed_values));
68 // Place the new setting in the existing serialized 'data' column.
69 $data = db_query("SELECT data FROM {field_config} WHERE id = :id", array(':id' => $field['id']))->fetchField();
70 $data = unserialize($data);
71 $data['settings']['allowed_values'] = $allowed_values;
72 $update['data'] = serialize($data);
75 // Rename field types.
76 $types = array('list' => 'list_integer', 'list_number' => 'list_float');
77 if (isset($types[$field['type']])) {
78 $update['type'] = $types[$field['type']];
83 $query = db_update('field_config')
84 ->condition('id', $field['id'])
92 * Helper function for list_update_7001: extract allowed values from a string.
94 * This reproduces the parsing logic in use before D7 RC2.
96 function _list_update_7001_extract_allowed_values($string, $position_keys) {
99 $list = explode("\n", $string);
100 $list = array_map('trim', $list);
101 $list = array_filter($list, 'strlen');
103 foreach ($list as $key => $value) {
104 // Check for a manually specified key.
105 if (strpos($value, '|') !== FALSE) {
106 list($key, $value) = explode('|', $value);
108 // Otherwise see if we need to use the value as the key. The "list" type
109 // will automatically convert non-keyed lines to integers.
110 elseif (!$position_keys) {
113 $values[$key] = (isset($value) && $value !== '') ? $value : $key;
120 * @addtogroup updates-7.x-extra
125 * Re-apply list_update_7001() for deleted fields.
127 function list_update_7002() {
128 // See http://drupal.org/node/1022924: list_update_7001() intitally
129 // overlooked deleted fields, which then caused fatal errors when the fields
130 // were being purged.
131 // list_update_7001() has the required checks to ensure it is reentrant, so
132 // it can simply be executed once more..
137 * @} End of "addtogroup updates-7.x-extra".