You are here

function custom_formatters_autocomplete in Custom Formatters 6

Menu callback; Retrieve a JSON object containing autocomplete suggestions for cck widgets.

1 string reference to 'custom_formatters_autocomplete'
custom_formatters_menu in ./custom_formatters.module
Implements hook_menu().

File

./custom_formatters.admin.inc, line 1126
Contains administration functions for the Custom Formatters module.

Code

function custom_formatters_autocomplete($string = '') {

  // The user enters a comma-separated list of fields. We only autocomplete the last tag.
  $array = drupal_explode_tags($string);

  // Fetch last field.
  $last_string = trim(array_pop($array));
  $matches = array();
  if ($last_string != '') {
    $prefix = count($array) ? implode(', ', $array) . ', ' : '';
    $fields = _content_field_types();

    // Give modules a chance to alter fields.
    drupal_alter('custom_formatters_fields', $fields);
    $fields = array_keys($fields);
    sort($fields);
    foreach ($fields as $field) {
      if (preg_match('/^' . drupal_strtolower($last_string) . '/', $field)) {
        $matches[$prefix . $field] = check_plain($field);
      }
    }
  }
  drupal_json($matches);
}