You are here

public function TourUIController::getModules in Tour UI 8

Returns list of modules included as part of the URL string.

Parameters

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

Return value

\Symfony\Component\HttpFoundation\JsonResponse Return list in JSON format.

1 string reference to 'TourUIController::getModules'
tour_ui.routing.yml in ./tour_ui.routing.yml
tour_ui.routing.yml

File

src/Controller/TourUIController.php, line 58

Class

TourUIController
Tour UI Controller.

Namespace

Drupal\tour_ui\Controller

Code

public function getModules(Request $request) {
  $matches = [];
  $part = $request->query
    ->get('q');
  if ($part) {
    $matches[] = $part;

    // Escape user input.
    $part = preg_quote($part);
    $modules = $this->moduleHandler
      ->getModuleList();
    foreach ($modules as $module => $data) {
      if (preg_match("/{$part}/", $module)) {
        $matches[] = $module;
      }
    }
  }
  return new JsonResponse($matches);
}