protected function WebformLikert::formatTextItem in Webform 8.5
Same name and namespace in other branches
- 6.x src/Plugin/WebformElement/WebformLikert.php \Drupal\webform\Plugin\WebformElement\WebformLikert::formatTextItem()
Format an element's value as text.
Parameters
array $element: An element.
\Drupal\webform\WebformSubmissionInterface $webform_submission: A webform submission.
array $options: An array of options.
Return value
string The element's value formatted as text.
Overrides WebformElementBase::formatTextItem
See also
_webform_token_get_submission_value()
File
- src/
Plugin/ WebformElement/ WebformLikert.php, line 195
Class
- WebformLikert
- Provides a 'likert' element.
Namespace
Drupal\webform\Plugin\WebformElementCode
protected function formatTextItem(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
$value = $this
->getValue($element, $webform_submission, $options);
$format = $this
->getItemFormat($element);
switch ($format) {
case 'raw':
$list = [];
foreach ($element['#questions'] as $question_key => $question_label) {
$answer_value = isset($value[$question_key]) ? $value[$question_key] : NULL;
$list[] = "{$question_key}: {$answer_value}";
}
return implode(PHP_EOL, $list);
default:
case 'value':
case 'table':
case 'list':
$list = [];
foreach ($element['#questions'] as $question_key => $question_label) {
$answer_value = isset($value[$question_key]) ? $value[$question_key] : NULL;
$answer_text = WebformOptionsHelper::getOptionText($answer_value, $element['#answers'], TRUE);
$list[] = "{$question_label}: {$answer_text}";
}
return implode(PHP_EOL, $list);
}
}