function _list_update_7001_extract_allowed_values

7.x list.install _list_update_7001_extract_allowed_values($string, $position_keys)

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

File

drupal-7.x/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);
    }
    // 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) {
      $key = $value;
    }
    $values[$key] = (isset($value) && $value !== '') ? $value : $key;
  }

  return $values;
}