protected function WebformElementController::getMatchesFromOptions in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Controller/WebformElementController.php \Drupal\webform\Controller\WebformElementController::getMatchesFromOptions()
Get matches from options.
Parameters
string $q: String to filter option's label by.
array $options: An associative array of webform 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 WebformElementController::getMatchesFromOptions()
- WebformElementController::autocomplete in src/
Controller/ WebformElementController.php - Returns response for the element autocomplete route.
File
- src/
Controller/ WebformElementController.php, line 162
Class
- WebformElementController
- Provides route responses for Webform elements.
Namespace
Drupal\webform\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);
}