function BooleanFormatter::viewElements
Builds a renderable array for a field value.
Parameters
\Drupal\Core\Field\FieldItemListInterface $items: The field values to be rendered.
string $langcode: The language that should be used to render the field.
Return value
array A renderable array for $items, as an array of child elements keyed by consecutive numeric indexes starting from 0.
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.
