public function ZoneSelectionForm::autocompleteZone in CloudFlare 8
Retrieves suggestions for zone autocompletion.
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 'ZoneSelectionForm::autocompleteZone'
File
- src/
Form/ ZoneSelectionForm.php, line 236
Class
- ZoneSelectionForm
- Class ZoneSelectionForm.
Namespace
Drupal\cloudflare\FormCode
public function autocompleteZone(Request $request) {
$zone_autocomplete_text = $request->query
->get('q');
$matches = [];
// Tracks if the current CloudFlare account has multiple zones.
/** @var \CloudFlarePhpSdk\ApiTypes\Zone\Zone $zone */
foreach ($this->zoneApi
->listZones() as $zone) {
if (stripos($zone
->getName(), $zone_autocomplete_text) === 0) {
$matches[] = [
'value' => $zone
->getZoneId(),
'label' => $zone
->getName(),
];
}
}
return new JsonResponse($matches);
}