You are here

public function PlainStringFormatter::viewElements in String field formatter 8.x

Same name and namespace in other branches
  1. 8 src/Plugin/Field/FieldFormatter/PlainStringFormatter.php \Drupal\string_field_formatter\Plugin\Field\FieldFormatter\PlainStringFormatter::viewElements()
  2. 2.0.x src/Plugin/Field/FieldFormatter/PlainStringFormatter.php \Drupal\string_field_formatter\Plugin\Field\FieldFormatter\PlainStringFormatter::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

src/Plugin/Field/FieldFormatter/PlainStringFormatter.php, line 92
Contains \Drupal\string_field_formatter\Plugin\Field\FieldFormatter\PlainStringFormatter.

Class

PlainStringFormatter
Plugin implementation of the 'plain_string_formatter' formatter.

Namespace

Drupal\string_field_formatter\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {
  $elements = array();
  $wrap_tag = $this
    ->getSetting('wrap_tag');
  if ('_none' == $wrap_tag) {
    $wrap_tag = '';
  }
  foreach ($items as $delta => $item) {
    $elements[$delta] = array(
      '#type' => 'html_tag',
      '#tag' => $wrap_tag,
      '#value' => $item->value,
    );
  }
  return $elements;
}