class CategoryAutocompleteController in Monitoring 8
Returns auto complete responses for sensor categories.
Hierarchy
- class \Drupal\monitoring\Controller\CategoryAutocompleteController
Expanded class hierarchy of CategoryAutocompleteController
File
- src/
Controller/ CategoryAutocompleteController.php, line 17 - Contains \Drupal\monitoring\Controller\CategoryAutocompleteController.
Namespace
Drupal\monitoring\ControllerView source
class CategoryAutocompleteController {
/**
* Retrieves suggestions for sensor category auto completion.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request.
*
* @return \Symfony\Component\HttpFoundation\JsonResponse
* A JSON response containing autocomplete suggestions.
*/
public function autocomplete(Request $request) {
// Stores the sensor categories.
$configs = monitoring_sensor_manager()
->getAllSensorConfig();
$categories = array();
foreach ($configs as $conf) {
$category = $conf->category;
if (!in_array($category, $categories)) {
$categories[] = $category;
}
}
$matches = array();
// Create the pattern to search in categories.
$pattern = '/^' . $request->query
->get('q') . '/i';
$prefixMatches = preg_grep($pattern, $categories);
foreach ($prefixMatches as $config) {
$matches[] = array(
'value' => $config,
'label' => new HtmlEscapedText($config),
);
}
return new JsonResponse($matches);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CategoryAutocompleteController:: |
public | function | Retrieves suggestions for sensor category auto completion. |