You are here

public function ConfigAutocompleteController::autocomplete in Monitoring 8

Retrieves suggestions for config auto completion.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The current request.

Return value

\Symfony\Component\HttpFoundation\JsonResponse A JSON response containing autocomplete suggestions.

1 string reference to 'ConfigAutocompleteController::autocomplete'
monitoring.routing.yml in ./monitoring.routing.yml
monitoring.routing.yml

File

src/Controller/ConfigAutocompleteController.php, line 28
Contains \Drupal\monitoring\Controller\ConfigAutocompleteController.

Class

ConfigAutocompleteController
Returns auto complete responses for config.

Namespace

Drupal\monitoring\Controller

Code

public function autocomplete(Request $request) {
  $matches = array();
  $prefixMatches = array_slice(\Drupal::service('config.factory')
    ->listAll($request->query
    ->get('q')), 0, 10);
  foreach ($prefixMatches as $config) {
    $matches[] = array(
      'value' => $config,
      'label' => new HtmlEscapedText($config),
    );
  }
  return new JsonResponse($matches);
}