public function LingotekSupportedLocalesController::autocomplete in Lingotek Translation 3.3.x
Same name and namespace in other branches
- 4.0.x src/Controller/LingotekSupportedLocalesController.php \Drupal\lingotek\Controller\LingotekSupportedLocalesController::autocomplete()
- 3.1.x src/Controller/LingotekSupportedLocalesController.php \Drupal\lingotek\Controller\LingotekSupportedLocalesController::autocomplete()
- 3.2.x src/Controller/LingotekSupportedLocalesController.php \Drupal\lingotek\Controller\LingotekSupportedLocalesController::autocomplete()
- 3.4.x src/Controller/LingotekSupportedLocalesController.php \Drupal\lingotek\Controller\LingotekSupportedLocalesController::autocomplete()
- 3.5.x src/Controller/LingotekSupportedLocalesController.php \Drupal\lingotek\Controller\LingotekSupportedLocalesController::autocomplete()
- 3.6.x src/Controller/LingotekSupportedLocalesController.php \Drupal\lingotek\Controller\LingotekSupportedLocalesController::autocomplete()
- 3.7.x src/Controller/LingotekSupportedLocalesController.php \Drupal\lingotek\Controller\LingotekSupportedLocalesController::autocomplete()
- 3.8.x src/Controller/LingotekSupportedLocalesController.php \Drupal\lingotek\Controller\LingotekSupportedLocalesController::autocomplete()
Callback for the autocomplete of supported locales.
Parameters
\Symfony\Component\HttpFoundation\Request $request: The request.
Return value
\Symfony\Component\HttpFoundation\JsonResponse A JSON response containing the autocomplete suggestions.
1 string reference to 'LingotekSupportedLocalesController::autocomplete'
File
- src/
Controller/ LingotekSupportedLocalesController.php, line 66
Class
Namespace
Drupal\lingotek\ControllerCode
public function autocomplete(Request $request) {
// Get autocomplete query.
$q = $request->query
->get('q') ?: '';
if ($q == '') {
return new JsonResponse([]);
}
$locales = $this->lingotek
->getLocalesInfo();
ksort($locales);
$matches = [];
foreach ($locales as $locale => $locale_info) {
$fieldsToSearch = [
'code' => $this
->t('Code'),
'language_code' => $this
->t('Language Code'),
// 'title' => $this->t('Title'),
// 'language' => $this->t('Language'),
'country_code' => $this
->t('Country Code'),
];
foreach ($fieldsToSearch as $field => $fieldDescription) {
if (stripos($locale_info[$field], $q) !== FALSE) {
$matches[] = [
'value' => $locale,
'label' => new FormattableMarkup('@title (@code) [matched: @match: %value]', [
'@title' => Html::escape($locale_info['title']),
'@code' => Html::escape($locale_info['code']),
'@match' => Html::escape($fieldDescription),
'%value' => Html::escape($locale_info[$field]),
]),
];
continue 2;
}
}
}
return new JsonResponse($matches);
}