You are here

protected function WebformToggle::formatTextItem in Webform 8.5

Same name and namespace in other branches
  1. 6.x modules/webform_toggles/src/Plugin/WebformElement/WebformToggle.php \Drupal\webform_toggles\Plugin\WebformElement\WebformToggle::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 BooleanBase::formatTextItem

See also

_webform_token_get_submission_value()

File

modules/webform_toggles/src/Plugin/WebformElement/WebformToggle.php, line 44

Class

WebformToggle
Provides a 'toggle' element.

Namespace

Drupal\webform_toggles\Plugin\WebformElement

Code

protected function formatTextItem(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
  $value = $this
    ->getValue($element, $webform_submission, $options);
  $format = $this
    ->getItemFormat($element);
  switch ($format) {
    case 'value':
      $on_text = !empty($element['#on_text']) ? $element['#on_text'] : $this
        ->t('Yes');
      $off_text = !empty($element['#off_text']) ? $element['#off_text'] : $this
        ->t('No');
      return $value ? $on_text : $off_text;
    case 'raw':
    default:
      return $value ? 1 : 0;
  }
}