function list_update_7001

Rename the list field types and change 'allowed_values' format.

1 call to list_update_7001()
list_update_7002 in modules/field/modules/list/list.install
Re-apply list_update_7001() for deleted fields.

File

modules/field/modules/list/list.install, line 51

Code

function list_update_7001() {
    $fields = _update_7000_field_read_fields(array(
        'module' => 'list',
    ));
    foreach ($fields as $field) {
        $update = array();
        // Translate the old string format into the new array format.
        $allowed_values = $field['settings']['allowed_values'];
        if (is_string($allowed_values)) {
            $position_keys = $field['type'] == 'list';
            $allowed_values = _list_update_7001_extract_allowed_values($allowed_values, $position_keys);
            // Additionally, float keys need to be disambiguated ('.5' is '0.5').
            if ($field['type'] == 'list_number' && !empty($allowed_values)) {
                $keys = array_map('_list_update_7001_float_string_cast', array_keys($allowed_values));
                $allowed_values = array_combine($keys, array_values($allowed_values));
            }
            // Place the new setting in the existing serialized 'data' column.
            $data = db_query("SELECT data FROM {field_config} WHERE id = :id", array(
                ':id' => $field['id'],
            ))->fetchField();
            $data = unserialize($data);
            $data['settings']['allowed_values'] = $allowed_values;
            $update['data'] = serialize($data);
        }
        // Rename field types.
        $types = array(
            'list' => 'list_integer',
            'list_number' => 'list_float',
        );
        if (isset($types[$field['type']])) {
            $update['type'] = $types[$field['type']];
        }
        // Save the new data.
        if ($update) {
            $query = db_update('field_config')->condition('id', $field['id'])
                ->fields($update)
                ->execute();
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.