You are here

public static function WebformOptionsHelper::getOptionDescription in Webform 6.x

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

Get the description 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 description if found or an empty string.

2 calls to WebformOptionsHelper::getOptionDescription()
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.

File

src/Utility/WebformOptionsHelper.php, line 157

Class

WebformOptionsHelper
Helper class webform options based methods.

Namespace

Drupal\webform\Utility

Code

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