You are here

public static function WebformOptionsHelper::getOptionText in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Utility/WebformOptionsHelper.php \Drupal\webform\Utility\WebformOptionsHelper::getOptionText()

Get the text string for an option value.

Parameters

string $value: The option value.

array $options: An associative array of options.

bool $options_description: Remove description which is delimited using ' -- '.

Return value

string The option text if found or the option value.

13 calls to WebformOptionsHelper::getOptionText()
OptionsBase::formatHtmlItem in src/Plugin/WebformElement/OptionsBase.php
Format an element's value as HTML.
OptionsBase::formatTextItem in src/Plugin/WebformElement/OptionsBase.php
Format an element's value as text.
WebformCompositeBase::buildExportRecord in src/Plugin/WebformElement/WebformCompositeBase.php
Build an element's export row.
WebformElementBase::validateUnique in src/Plugin/WebformElementBase.php
Form API callback. Validate element #unique value.
WebformEntityConditionsManager::buildConditionItem in src/WebformEntityConditionsManager.php
Convert a condition's select, trigger, and value into a human read-able format.

... See full list

File

src/Utility/WebformOptionsHelper.php, line 123

Class

WebformOptionsHelper
Helper class webform options based methods.

Namespace

Drupal\webform\Utility

Code

public static function getOptionText($value, array $options, $options_description = FALSE) {
  foreach ($options as $option_value => $option_text) {
    if (is_array($option_text)) {
      $option_text = self::getOptionText($value, $option_text, $options_description);
      if ((string) $value !== (string) $option_text) {
        return $option_text;
      }
    }
    elseif ($value !== NULL && (string) $value === (string) $option_value) {
      if ($options_description && strpos($option_text, static::DESCRIPTION_DELIMITER) !== FALSE) {
        list($option_text) = static::splitOption($option_text);
        return $option_text;
      }
      else {
        return $option_text;
      }
    }
  }
  return $value;
}