protected function AssertContentTrait::getAllOptions in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::getAllOptions()
- 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\KernelTestsCode
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;
}