You are here

function select2widget_ajax_callback in Select2 Field Widget 7.2

Menu callback: autocomplete the label of an entity.

Parameters

$field_name: The name of the entity-reference field.

$entity_type: The entity type.

$bundle_name: The bundle name.

$entity_id: Optional; The entity ID the entity-reference field is attached to. Defaults to ''.

1 string reference to 'select2widget_ajax_callback'
select2widget_menu in ./select2widget.module
Implements hook_menu().

File

./select2widget.module, line 358

Code

function select2widget_ajax_callback($field_name, $entity_type, $bundle_name, $entity_id = '') {
  $string = '';
  if (isset($_GET['search_string']) && !empty($_GET['search_string'])) {
    $string = $_GET['search_string'];
  }
  $field = field_info_field($field_name);
  $instance = field_info_instance($entity_type, $field_name, $bundle_name);
  if ($instance['widget']['module'] == 'og_vocab' && module_exists('og_vocab')) {
    $vid = $_GET['vid'];
    $og_vocab = og_vocab_load_og_vocab($vid, $entity_type, $instance['bundle'], NULL, TRUE);
    if (isset($og_vocab)) {
      $mocked_field = $og_vocab
        ->getMockedField();
      $instance = $mocked_field['instance'];
      $field = $mocked_field['field'];
      $entity_type = $og_vocab->entity_type;
    }
  }
  $type = $field['type'];
  $function = "select2widget_" . $type . '_get_matches';
  drupal_alter('select2widget_get_matches', $function, $field, $instance, $entity_type);
  if (function_exists($function)) {
    return $function($field, $instance, $entity_type, $string, $entity_id);
  }
}