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 drupal/modules/field/modules/list/list.install
Rename the list field types and change 'allowed_values' format.

File

drupal/modules/field/modules/list/list.install, line 96
Install, update and uninstall functions for the list module.

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;
}