You are here

protected function WebformElementController::getMatchesFromOptionsRecursive in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Controller/WebformElementController.php \Drupal\webform\Controller\WebformElementController::getMatchesFromOptionsRecursive()

Get matches from options recursive.

Parameters

string $q: String to filter option's label by.

array $options: An associative array of webform options.

array $matches: An associative array of autocomplete matches.

string $operator: Match operator either CONTAINS or STARTS_WITH.

1 call to WebformElementController::getMatchesFromOptionsRecursive()
WebformElementController::getMatchesFromOptions in src/Controller/WebformElementController.php
Get matches from options.

File

src/Controller/WebformElementController.php, line 196

Class

WebformElementController
Provides route responses for Webform elements.

Namespace

Drupal\webform\Controller

Code

protected function getMatchesFromOptionsRecursive($q, array $options, array &$matches, $operator = 'CONTAINS') {
  foreach ($options as $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,
      ];
    }
  }
}