You are here

function rooms_availability_reference_autocomplete in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7

Menu callback for the autocomplete results.

4 string references to 'rooms_availability_reference_autocomplete'
FeatureContext::iAddTheAvailabilityReferenceFieldReferencingToUnitsInPageContent in test/features/bootstrap/FeatureContext.php
Adds availability reference field to a content type.
rooms_availability_reference_field_info in modules/rooms_availability_reference/rooms_availability_reference.module
Implements hook_field_info().
rooms_availability_reference_field_widget_form in modules/rooms_availability_reference/rooms_availability_reference.module
Implements hook_field_widget_form().
rooms_availability_reference_menu in modules/rooms_availability_reference/rooms_availability_reference.module
Implements hook_menu().

File

modules/rooms_availability_reference/rooms_availability_reference.module, line 338
Defines a field type for referencing availability information

Code

function rooms_availability_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,
  );
  $references = rooms_availability_reference_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);
}