You are here

public static function YamlFormOptionsHelper::getOptionText in YAML Form 8

Get the text string for an option value.

Parameters

string $value: The option value.

array $options: An associative array of options.

Return value

string The option text if found or the option value.

8 calls to YamlFormOptionsHelper::getOptionText()
OptionsBase::buildExportRecord in src/Plugin/YamlFormElement/OptionsBase.php
Build an element's export row.
OptionsBase::formatText in src/Plugin/YamlFormElement/OptionsBase.php
Format an element's value as plain text.
YamlFormCompositeBase::buildExportRecord in src/Plugin/YamlFormElement/YamlFormCompositeBase.php
Build an element's export row.
YamlFormLikert::buildExportRecord in src/Plugin/YamlFormElement/YamlFormLikert.php
Build an element's export row.
YamlFormLikert::formatHtml in src/Plugin/YamlFormElement/YamlFormLikert.php
Format an element's value as HTML.

... See full list

File

src/Utility/YamlFormOptionsHelper.php, line 64

Class

YamlFormOptionsHelper
Helper class form options based methods.

Namespace

Drupal\yamlform\Utility

Code

public static function getOptionText($value, array $options) {
  foreach ($options as $option_value => $option_text) {
    if (is_array($option_text)) {
      if ($text = self::getOptionText($value, $option_text)) {
        return $text;
      }
    }
    elseif ($value == $option_value) {
      return $option_text;
    }
  }
  return $value;
}