function BooleanFormatter::viewElements
Same name in other branches
- 8.9.x core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/BooleanFormatter.php \Drupal\Core\Field\Plugin\Field\FieldFormatter\BooleanFormatter::viewElements()
- 10 core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/BooleanFormatter.php \Drupal\Core\Field\Plugin\Field\FieldFormatter\BooleanFormatter::viewElements()
- 11.x core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/BooleanFormatter.php \Drupal\Core\Field\Plugin\Field\FieldFormatter\BooleanFormatter::viewElements()
Overrides FormatterInterface::viewElements
File
-
core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldFormatter/ BooleanFormatter.php, line 139
Class
- BooleanFormatter
- Plugin implementation of the 'boolean' formatter.
Namespace
Drupal\Core\Field\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
$formats = $this->getOutputFormats();
foreach ($items as $delta => $item) {
$format = $this->getSetting('format');
if ($format == 'custom') {
$elements[$delta] = [
'#markup' => $item->value ? $this->getSetting('format_custom_true') : $this->getSetting('format_custom_false'),
];
}
else {
$elements[$delta] = [
'#markup' => $item->value ? $formats[$format][0] : $formats[$format][1],
];
}
}
return $elements;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.