You are here

function bat_event_reference_autocomplete in Booking and Availability Management Tools for Drupal 7

Menu callback for the autocomplete results.

3 string references to 'bat_event_reference_autocomplete'
bat_event_field_widget_form in modules/bat_event/bat_event.module
Implements hook_field_widget_form().
bat_event_menu in modules/bat_event/bat_event.module
Implements hook_menu().
bat_event_type_add_event_state_reference in modules/bat_event/bat_event.module
Create a field of type 'Bat Event State Reference' to reference an Event State.

File

modules/bat_event/bat_event.module, line 1860
Manage Events - Events store the EventValue of a Unit over a period of time.

Code

function bat_event_reference_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,
    'event_type' => $instance['settings']['event_type'],
  );
  $references = bat_event_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'] . " [state_id:{$id}]"] = '<div class="reference-autocomplete">' . $suggestion . '</div>';
  }
  drupal_json_output($matches);
}