You are here

public function AutocompleteController::autocomplete in Salesforce Suite 8.4

Same name and namespace in other branches
  1. 5.0.x modules/salesforce_mapping_ui/src/Controller/AutocompleteController.php \Drupal\salesforce_mapping_ui\Controller\AutocompleteController::autocomplete()

Autocomplete.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request object providing the autocomplete query parameter.

string $entity_type_id: The entity type filter options by.

string $bundle: The bundle of the entity to filter options by.

Return value

\Symfony\Component\HttpFoundation\JsonResponse The JSON results.

1 string reference to 'AutocompleteController::autocomplete'
salesforce_mapping_ui.routing.yml in modules/salesforce_mapping_ui/salesforce_mapping_ui.routing.yml
modules/salesforce_mapping_ui/salesforce_mapping_ui.routing.yml

File

modules/salesforce_mapping_ui/src/Controller/AutocompleteController.php, line 68

Class

AutocompleteController
Class AutocompleteController.

Namespace

Drupal\salesforce_mapping_ui\Controller

Code

public function autocomplete(Request $request, $entity_type_id, $bundle) {
  $string = Html::escape(mb_strtolower($request->query
    ->get('q')));
  $field_definitions = $this->fieldManager
    ->getFieldDefinitions($entity_type_id, $bundle);

  // Filter out EntityReference Items.
  foreach ($field_definitions as $index => $field_definition) {
    if ($field_definition
      ->getType() === 'entity_reference') {
      unset($field_definitions[$index]);
    }
  }
  $results = $this->dataFetcher
    ->autocompletePropertyPath($field_definitions, $string);
  return new JsonResponse($results);
}