You are here

function flipping_book_reference_autocomplete in Flipping Book 7

Menu callback for the autocomplete results.

3 string references to 'flipping_book_reference_autocomplete'
flipping_book_reference_field_widget_form in ./flipping_book_reference.module
Implements hook_field_widget_form().
flipping_book_reference_field_widget_settings_form in ./flipping_book_reference.module
Implements hook_field_widget_settings_form().
flipping_book_reference_menu in ./flipping_book_reference.module
Implements hook_menu().

File

./flipping_book_reference.module, line 671
Defines a field type for referencing one flipping_book from a node.

Code

function flipping_book_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 = flipping_book_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'] . " [fbid:{$id}]"] = '<div class="reference-autocomplete">' . $suggestion . '</div>';
  }
  drupal_json_output($matches);
  drupal_exit();
}