You are here

protected function YamlFormEntityElementsValidator::getDuplicateNamesRecursive in YAML Form 8

Recurse through elements and collect an associative array keyed by name and number of duplicate instances.

Parameters

array $elements: An array of elements.

array $names: An associative array keyed by name and number of duplicate instances.

1 call to YamlFormEntityElementsValidator::getDuplicateNamesRecursive()
YamlFormEntityElementsValidator::validateDuplicateNames in src/YamlFormEntityElementsValidator.php
Validate elements does not contain duplicate names.

File

src/YamlFormEntityElementsValidator.php, line 187

Class

YamlFormEntityElementsValidator
Defines a class to validate form elements.

Namespace

Drupal\yamlform

Code

protected function getDuplicateNamesRecursive(array $elements, array &$names) {
  foreach ($elements as $key => &$element) {
    if (Element::property($key) || !is_array($element)) {
      continue;
    }
    if (isset($element['#type'])) {
      if (!isset($names[$key])) {
        $names[$key] = 0;
      }
      else {
        ++$names[$key];
      }
    }
    $this
      ->getDuplicateNamesRecursive($element, $names);
  }
}