function _list_update_7001_extract_allowed_values

Helper function for list_update_7001: extract allowed values from a string.

This reproduces the parsing logic in use before D7 RC2.

1 call to _list_update_7001_extract_allowed_values()
list_update_7001 in modules/field/modules/list/list.install
Rename the list field types and change 'allowed_values' format.

File

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

Code

function _list_update_7001_extract_allowed_values($string, $position_keys) {
    $values = array();
    $list = explode("\n", $string);
    $list = array_map('trim', $list);
    $list = array_filter($list, 'strlen');
    foreach ($list as $key => $value) {
        // Check for a manually specified key.
        if (strpos($value, '|') !== FALSE) {
            list($key, $value) = explode('|', $value);
        }
        elseif (!$position_keys) {
            $key = $value;
        }
        $values[$key] = isset($value) && $value !== '' ? $value : $key;
    }
    return $values;
}

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