public function OptionsKeyFormatter::viewElements

Builds a renderable array for a field value.

Parameters

Drupal\Core\Entity\EntityInterface $entity: The entity being displayed.

string $langcode: The language associated with $items.

array $items: Array of values for this field.

Return value

array A renderable array for $items, as an array of child elements keyed by numeric indexes starting from 0.

Overrides FormatterInterface::viewElements

File

drupal/core/modules/options/lib/Drupal/options/Plugin/field/formatter/OptionsKeyFormatter.php, line 35
Contains \Drupal\options\Plugin\field\formatter\OptionsKeyFormatter.

Class

OptionsKeyFormatter
Plugin implementation of the 'list_key' formatter.

Namespace

Drupal\options\Plugin\field\formatter

Code

public function viewElements(EntityInterface $entity, $langcode, array $items) {
  $elements = array();
  foreach ($items as $delta => $item) {
    $elements[$delta] = array(
      '#markup' => field_filter_xss($item['value']),
    );
  }
  return $elements;
}