You are here

protected function BooleanBase::formatTextItem in Webform 8.5

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

1 method overrides BooleanBase::formatTextItem()
WebformToggle::formatTextItem in modules/webform_toggles/src/Plugin/WebformElement/WebformToggle.php
Format an element's value as text.

File

src/Plugin/WebformElement/BooleanBase.php, line 30

Class

BooleanBase
Provides a base 'boolean' class.

Namespace

Drupal\webform\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':
      return $value ? $this
        ->t('Yes') : $this
        ->t('No');
    default:

      // If a #return_value is defined then return it.
      if (!empty($element['#return_value'])) {
        return $value ? $value : 0;
      }
      else {
        return $value ? 1 : 0;
      }
  }
}