You are here

function _name_field_get_options in Name Field 7

2 calls to _name_field_get_options()
name_field_get_options in ./name.module
Name autocomplete data sources callback.
_name_devel_generate_name in ./name.devel_generate.inc
Helper function to generate set of fake names.

File

includes/name.content.inc, line 564
Provides additional Field functionality for the name module.

Code

function _name_field_get_options($field, $key) {
  _name_defaults($field['settings'], 'settings');
  $fs = $field['settings'];
  $options = array_filter(explode("\n", $fs[$key . '_options']));
  foreach ($options as $index => $opt) {
    if (preg_match(NAME_FIELD_TAXONOMY_OPTION_REGEX, trim($opt), $matches)) {
      unset($options[$index]);
      if (module_exists('taxonomy')) {
        if ($vid = _name_get_vocabulary_id_by_code_or_number($matches[1])) {
          $max_length = isset($fs['max_length'][$key]) ? $fs['max_length'][$key] : 255;
          foreach (taxonomy_get_tree($vid) as $term) {
            if (drupal_strlen($term->name) <= $max_length) {
              $options[] = $term->name;
            }
          }
        }
      }
    }
  }

  // Options could come from multiple sources, filter duplicates.
  $options = array_unique($options);
  if (isset($fs['sort_options']) && !empty($fs['sort_options'][$key])) {
    natcasesort($options);
  }
  $default = FALSE;
  foreach ($options as $index => $opt) {
    if (strpos($opt, '--') === 0) {
      unset($options[$index]);
      $default = drupal_substr($opt, 2);
    }
  }
  $options = drupal_map_assoc(array_map('trim', $options));
  if ($default !== FALSE) {
    $options = array(
      '' => $default,
    ) + $options;
  }
  return $options;
}