function BooleanFormatter::viewElements

Same name in other branches
  1. 9 core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/BooleanFormatter.php \Drupal\Core\Field\Plugin\Field\FieldFormatter\BooleanFormatter::viewElements()
  2. 10 core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/BooleanFormatter.php \Drupal\Core\Field\Plugin\Field\FieldFormatter\BooleanFormatter::viewElements()
  3. 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\FieldFormatter

Code

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.