You are here

public static function WebformOptions::convertOptionsToValues in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Element/WebformOptions.php \Drupal\webform\Element\WebformOptions::convertOptionsToValues()

Convert options to values for webform_multiple element.

Parameters

array $options: An array of options.

bool $options_description: Options has description.

Return value

array An array of values.

2 calls to WebformOptions::convertOptionsToValues()
WebformOptions::processWebformOptions in src/Element/WebformOptions.php
Process options and build options widget.
WebformOptions::valueCallback in src/Element/WebformOptions.php
Determines how user input is mapped to an element's #value property.

File

src/Element/WebformOptions.php, line 262

Class

WebformOptions
Provides a webform element to assist in creation of options.

Namespace

Drupal\webform\Element

Code

public static function convertOptionsToValues(array $options = [], $options_description = FALSE) {
  $values = [];
  foreach ($options as $value => $text) {
    if ($options_description && WebformOptionsHelper::hasOptionDescription($text)) {
      list($text, $description) = WebformOptionsHelper::splitOption($text);
      $values[$value] = [
        'text' => $text,
        'description' => $description,
      ];
    }
    else {
      $values[$value] = [
        'text' => $text,
      ];
    }
  }
  return $values;
}