You are here

function user_relationship_views_ajax_autocomplete_relationships_type in User Relationships 7

Same name and namespace in other branches
  1. 6 user_relationship_views/user_relationship_views.module \user_relationship_views_ajax_autocomplete_relationships_type()

Page callback for views user relationship types autocomplete

1 string reference to 'user_relationship_views_ajax_autocomplete_relationships_type'
user_relationship_views_menu in user_relationship_views/user_relationship_views.module
Implements hook_menu().

File

user_relationship_views/user_relationship_views.module, line 37
User Relationships Views integration. @author Alex Karshakevich http://drupal.org/user/183217

Code

function user_relationship_views_ajax_autocomplete_relationships_type($string = '') {

  // The same implementation as in admin/views/ajax/autocomplete/user
  // The user enters a comma-separated list of tags. We only autocomplete the last tag.
  $array = drupal_explode_tags($string);

  // Fetch last tag
  $last_string = trim(array_pop($array));
  $matches = array();
  if ($last_string != '') {
    $prefix = count($array) ? implode(', ', $array) . ', ' : '';
    foreach (user_relationships_types_load() as $rtype) {
      if (stripos($rtype->name, $string) === 0) {
        $n = $rtype->name;

        // Commas and quotes in terms are special cases, so encode 'em.
        if (strpos($rtype->name, ',') !== FALSE || strpos($rtype->name, '"') !== FALSE) {
          $n = '"' . str_replace('"', '""', $rtype->name) . '"';
        }
        $matches[$prefix . $n] = check_plain(user_relationships_type_get_name($rtype));
      }
    }
  }
  drupal_json_output($matches);
}