You are here

public function DefaultController::demo_autocomplete in Demonstration site (Sandbox / Snapshot) 8

funtion to autocomplete the demo dump and save it to the dumppath declared in settings.php

1 string reference to 'DefaultController::demo_autocomplete'
demo.routing.yml in ./demo.routing.yml
demo.routing.yml

File

src/Controller/DefaultController.php, line 18

Class

DefaultController
Default controller for the demo module.

Namespace

Drupal\demo\Controller

Code

public function demo_autocomplete($string = '') {
  $matches = [];
  if ($string && ($fileconfig = demo_get_fileconfig())) {
    $string = preg_quote($string);
    $files = \Drupal::service('file_system')
      ->scanDirectory($fileconfig['dumppath'], '/' . $string . '.*\\.info$/');
    foreach ($files as $file) {
      $matches[$file->name] = check_plain($file->name);
    }
  }
  return new JsonResponse($matches, 200);
}