function AssertContentTrait::getAllOptions

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::getAllOptions()
  2. 8.9.x core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::getAllOptions()
  3. 11.x 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.

1 call to AssertContentTrait::getAllOptions()
AssertContentTrait::assertFieldsByValue in core/tests/Drupal/KernelTests/AssertContentTrait.php
Asserts that a field exists in the current page with a given Xpath result.

File

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

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.