You are here

protected static function WebformElementStates::convertOptionToItemList in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Element/WebformElementStates.php \Drupal\webform\Element\WebformElementStates::convertOptionToItemList()

Convert options with optgroup to item list.

Parameters

array $options: An array of options.

Return value

array A renderable array.

1 call to WebformElementStates::convertOptionToItemList()
WebformElementStates::buildSourceHelp in src/Element/WebformElementStates.php
Build edit source help.

File

src/Element/WebformElementStates.php, line 327

Class

WebformElementStates
Provides a webform element to edit an element's #states.

Namespace

Drupal\webform\Element

Code

protected static function convertOptionToItemList(array $options) {
  $items = [];
  foreach ($options as $option_name => $option_value) {
    if (is_array($option_value)) {
      $items[$option_name] = [
        'title' => [
          '#markup' => $option_name,
        ],
        'children' => [
          '#theme' => 'item_list',
          '#items' => array_keys($option_value),
        ],
      ];
    }
    else {
      $items[$option_name] = [
        '#markup' => $option_name,
        '#prefix' => '<div>',
        '#suffix' => '</div>',
      ];
    }
  }
  return [
    '#theme' => 'item_list',
    '#items' => $items,
  ];
}