You are here

protected function AssertContentTrait::getAllOptions in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::getAllOptions()
  2. 9 core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::getAllOptions()

Get all option elements, including nested options, in a select.

Parameters

\SimpleXMLElement $element: The element for which to get the options.

Return value

\SimpleXmlElement[] Option elements in select.

File

core/tests/Drupal/KernelTests/AssertContentTrait.php, line 248

Class

AssertContentTrait
Provides test methods to assert content.

Namespace

Drupal\KernelTests

Code

protected function getAllOptions(\SimpleXMLElement $element) {
  $options = [];

  // Add all options items.
  foreach ($element->option as $option) {
    $options[] = $option;
  }

  // Search option group children.
  if (isset($element->optgroup)) {
    $nested_options = [];
    foreach ($element->optgroup as $group) {
      $nested_options[] = $this
        ->getAllOptions($group);
    }
    $options = array_merge($options, ...$nested_options);
  }
  return $options;
}