public function YamlFormToggle::formatText in YAML Form 8
Format an element's value as plain text.
Parameters
array $element: An element.
array|mixed $value: A value.
array $options: An array of options.
Return value
string The element's value formatted as plain text or a render array.
Overrides BooleanBase::formatText
File
- src/
Plugin/ YamlFormElement/ YamlFormToggle.php, line 35
Class
- YamlFormToggle
- Provides a 'toggle' element.
Namespace
Drupal\yamlform\Plugin\YamlFormElementCode
public function formatText(array &$element, $value, array $options = []) {
$format = $this
->getFormat($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;
}
}