protected function YamlFormElementController::getMatchesFromOptions in YAML Form 8
Get matches from options.
Parameters
string $q: String to filter option's label by.
array $options: An associative array of form options.
string $operator: Match operator either CONTAINS or STARTS_WITH.
int $limit: Limit number of matches.
Return value
array An array of matches sorted by label.
1 call to YamlFormElementController::getMatchesFromOptions()
- YamlFormElementController::autocomplete in src/
Controller/ YamlFormElementController.php - Returns response for the element autocomplete route.
File
- src/
Controller/ YamlFormElementController.php, line 161
Class
- YamlFormElementController
- Provides route responses for form element.
Namespace
Drupal\yamlform\ControllerCode
protected function getMatchesFromOptions($q, array $options, $operator = 'CONTAINS', $limit = 10) {
// Make sure options are populated.
if (empty($options)) {
return [];
}
$matches = [];
// Filter and convert options to autocomplete matches.
$this
->getMatchesFromOptionsRecursive($q, $options, $matches, $operator);
// Sort matches.
ksort($matches);
// Apply match limit.
if ($limit) {
$matches = array_slice($matches, 0, $limit);
}
return array_values($matches);
}