You are here

function bat_calendar_reference_units_autocomplete in Booking and Availability Management Tools for Drupal 7

Menu callback for the units autocomplete results.

1 string reference to 'bat_calendar_reference_units_autocomplete'
bat_calendar_reference_menu in modules/bat_calendar_reference/bat_calendar_reference.module
Implements hook_menu().

File

modules/bat_calendar_reference/bat_calendar_reference.module, line 634
Defines a field type for referencing event information.

Code

function bat_calendar_reference_units_autocomplete($entity_type, $bundle, $field_name, $string = '') {
  $field = field_info_field($field_name);
  $instance = field_info_instance($entity_type, $field_name, $bundle);
  $options = array(
    'string' => $string,
    'match' => $instance['widget']['settings']['autocomplete_match'],
    'limit' => 10,
  );
  $references = bat_calendar_reference_units_potential_references($field, $options);
  $matches = array();
  foreach ($references as $id => $row) {

    // Markup is fine in autocompletion results (might happen when rendered
    // through Views) but we want to remove hyperlinks.
    $suggestion = preg_replace('/<a href="([^<]*)">([^<]*)<\\/a>/', '$2', $row['rendered']);

    // Add a class wrapper for a few required CSS overrides.
    $matches[$row['title'] . " [unit_id:{$id}]"] = '<div class="reference-autocomplete">' . $suggestion . '</div>';
  }
  drupal_json_output($matches);
}