protected function YamlFormElementController::getMatchesFromOptionsRecursive in YAML Form 8
Get matches from options recursive.
Parameters
string $q: String to filter option's label by.
array $options: An associative array of form options.
array $matches: An associative array of autocomplete matches.
string $operator: Match operator either CONTAINS or STARTS_WITH.
1 call to YamlFormElementController::getMatchesFromOptionsRecursive()
- YamlFormElementController::getMatchesFromOptions in src/
Controller/ YamlFormElementController.php - Get matches from options.
File
- src/
Controller/ YamlFormElementController.php, line 195
Class
- YamlFormElementController
- Provides route responses for form element.
Namespace
Drupal\yamlform\ControllerCode
protected function getMatchesFromOptionsRecursive($q, array $options, array &$matches, $operator = 'CONTAINS') {
foreach ($options as $value => $label) {
if (is_array($label)) {
$this
->getMatchesFromOptionsRecursive($q, $label, $matches, $operator);
continue;
}
// Cast TranslatableMarkup to string.
$label = (string) $label;
if ($operator == 'STARTS_WITH' && stripos($label, $q) === 0) {
$matches[$label] = [
'value' => $label,
'label' => $label,
];
}
elseif (stripos($label, $q) !== FALSE) {
$matches[$label] = [
'value' => $label,
'label' => $label,
];
}
}
}