You are here

public function BooleanYesNo::viewElements in Boolean formatter 8

File

lib/Drupal/boolean_formatter/Plugin/field/formatter/BooleanYesNo.php, line 90
Contains \Drupal\boolean_formatter\Plugin\field\formatter\BooleanYesNo.

Class

BooleanYesNo
Plugin implementation of the 'boolean_formatter' formatter.

Namespace

Drupal\boolean_formatter\Plugin\field\formatter

Code

public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) {
  $elements = array();
  $values = options_allowed_values($this->fieldDefinition, $entity);
  foreach ($items as $delta => $item) {
    $value = !empty($values[1]) ? $item->value == $values[1] : !empty($item->value);
    $text = $this
      ->displayValueWithFormat($value, $this
      ->getSetting('format'), $this->settings);
    $elements[$delta] = array(
      '#markup' => field_filter_xss($text),
    );
  }
  return $elements;
}