You are here

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

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

Convert values from yamform_multiple element to options.

Parameters

array $values: An array of values.

bool $options_description: Options has description.

Return value

array An array of options.

1 call to WebformOptions::convertValuesToOptions()
WebformOptions::validateWebformOptions in src/Element/WebformOptions.php
Validates webform options element.

File

src/Element/WebformOptions.php, line 228

Class

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

Namespace

Drupal\webform\Element

Code

public static function convertValuesToOptions(array $values = NULL, $options_description = FALSE) {
  $options = [];
  if ($values && is_array($values)) {
    foreach ($values as $option_value => $option) {
      $option_text = $option['text'];
      if ($options_description && !empty($option['description'])) {
        $option_text .= WebformOptionsHelper::DESCRIPTION_DELIMITER . $option['description'];
      }

      // Populate empty option value or option text.
      if ($option_value === '') {
        $option_value = $option_text;
      }
      elseif ($option_text === '') {
        $option_text = $option_value;
      }
      $options[$option_value] = $option_text;
    }
  }
  return $options;
}